php取数组随机数
程序员文章站
2022-06-07 23:35:45
...
$a=Array ( [0] => Array ( [0] => 8 [face_amount] => 8 ) [1] => Array ( [0] => 30 [face_amount] => 30 ) [2] => Array ( [0] => 50 [face_amount] => 50 ) [3] => Array ( [0] => 50 [face_amount] => 50 ) );//从数据库里取出的数据
//二维数组取一个值
$b=(array_rand($a,1));
echo $a[$b]['face_amount'];
//二维数组取多个值
$c=(array_rand($a,2));
echo $a[$c[0]]['face_amount'];
echo $a[$c[1]]['face_amount'];
//定义一个二维数组
$a=array(
array("Volvo",22,18),
array("BMW",25,13),
array("Saab",5,2),
array("Land Rover",17,15)
);
//获取一个
$b=(array_rand($a,1));
var_dump($a[$b][0]);
//获取多个
$b=(array_rand($a,2));
var_dump($a[$b[0]][0]);
var_dump($a[$b[1]][1]);