我想随机化一个多维数组,回显这两个值,然后从数组中删除它。
对于一维数组,我只需要使用array_pop()函数。但既然不是,我就有点迷路了。
我已经做了一些代码,我将如何做,就像它是一个一维数组。
$id = array(
array(4534534, "JohnDoe"),
array(2432423, "Foobar"),
);
$random = $id; // make a copy of the array
shuffle($random); // randomize the order
//I think this part needs to be modified
//should echo out $random[0][0] and $random[0][1] for example
//then remove from the array
echo array_pop($random); 发布于 2014-03-07 21:48:29
你的代码完全正确。您唯一的错误是,您不能回显一个数组,您必须手动这样做:
$result = array_pop($random);
echo $result[0] . $result[1];发布于 2014-03-07 21:47:02
您可以将弹出的值存储在变量中,然后使用快速预测来回显它们。
$random = $id; // make a copy of the array
shuffle($random); // randomize the order
$samples = array_pop($random);
foreach ($samples as $sample){
echo $sample;
}https://stackoverflow.com/questions/22261111
复制相似问题