Php while循环中的数组_rand()必须相同

Php while循环中的数组_rand()必须相同,php,arrays,Php,Arrays,我有一个while循环,使用数组的值: while (blablabla) { $id = $scene[array_rand($scene)]; ... few mysql querys using $id } 每次使用$id我都会得到另一个值(是的,这是我想要的),但每次while运行另一个$id时,我都需要相同的值,但在while循环中,$id内的值在每个查询中都是相同的。有没有可能?为什么不在使用调用ID之前设置一次数组键 while

我有一个while循环,使用数组的值:

    while (blablabla) {
            $id = $scene[array_rand($scene)];

  ... few mysql querys using $id

     }

每次使用
$id
我都会得到另一个值(是的,这是我想要的),但每次while运行另一个
$id
时,我都需要相同的值,但在while循环中,
$id
内的值在每个查询中都是相同的。有没有可能?

为什么不在使用调用ID之前设置一次数组键

while (blablabla) {             
  $id = $scene[array_rand($scene)];   
  $new_id = $id; //create new variable and use this one in the rest of the queries
  ... few mysql querys using $new_id       
} 
while ()
{
  $key = array_rand($scene);
  $id = $scene[$key];

  //do something
}

为了确保我的理解正确:只要while循环在运行(比如元素1,4,8,2,…),您每次都想要随机元素,但是当您再次调用while时,您想要相同的序列(1,4,8,2,…)?请尽量改进措辞,以便我们了解你的意思。