Here is my code. I don't understand why am I in endless loop. I think $check has to stop the loop when I make unique random values for my array.
<?php
$foo["blue"] = 0;
$foo["black"] = 0;
$foo["red"] = 0;
$foo["white"] = 0;
$check;
do
{
foreach($foo as &$val)
{
$val = rand(1,6);
}
$foo = array_unique($foo);
$check = count($foo);
}
while($check != 4);
echo '............................ <br>';
foreach($foo as $key=>$value)
{
echo $key . ' ' . $value . '<br>';
}
?>
print_r($foo);in thedo-whileloop to see what the values are.foreachloop.$foo = array_unique($foo). If, after the first iteration, the array has duplicated values, then that line will make$fooan array of three or less elements, and thus$checkwill always be different than 4, thus the loop will be infinite. The only way the loop will stop is if you get four different random values after the first iteration.