Hi:
I would like to know how to use the function foreach with array_rand.
This is an example of what I would like to do.
$colors=array('red','green','blue','white','black');
$sc=array_rand($colors,2);
That is the array.
Now what I would like to achieve
echo $colors[$sc[0]];
echo $colors[$sc[1]];
But achieve it using foreach
foreach($colors[$sc] as $c => $r){
echo $c ."=>".$r;
}
I get this error
Warning: Illegal offset type in C:\www\test.php on line 5
line 5 would be the foreach function.
Thanks inm advance for anyone who helps.