I've been trying to randomly select one or more entries of a multidimensional array without much success. can anyone suggest a good method? In my code i've tried using array_rand, but doesn't always work.
Code: Select all
$this->obArr = array(200=>array(200=>array('blue circle',200, 200)),
100=>array(100=>array('blue triangle',100, 100)),
75=>array(75=>array('orange circle', 75, 75)),
300=>array(300=>array('orange triangle', 300, 300)),
10=>array(115=>array('red circle', 10, 115)),
25=>array(300=>array('red triangle', 25, 300)),
15=>array(100=>array('white square', 15, 100)));
$random_key = array_rand($this->obArr,1);
$random_key1 = array_rand($this->obArr[$random_key],1);
$this->a = array($this->obArr[$random_key][$random_key1]);
Code: Select all
$this->a = array($this->obArr[100][100], $this->obArr[25][300],$this->obArr[15][100]);