I have some code to generate 4 unique random numbers between 0-9: -
//Globals
$arr = array();
$gridMax = 9;
$i = 0;
while ( count($arr) < 4 ) {
$x = mt_rand(0, $gridMax);
if ( !in_array($x, $arr) ) {
$arr[] = $x;
}
}
print_r($arr);
I'm trying to create a grid and if the corresponding grid number is the same as one of the 4 unique values in my array then I want it to add some text to the $build variable. If not, do nothing: -
while ($i <= $gridMax) {
foreach ($arr as $value) {
if ($value == $i) {
$build = "build";
} else {
$build = "";
}
}
echo "<li class=\"map\">{$build}</li>";
$i++;
}
However, it only works for the final value in the last key (shown here): -
http://www.kryptonite-dove.com/sandbox/mt_rand/
Can anyone give me some pointers? I've been absent from coding for a number of months and my mind is a little foggy!