I’m having trouble pulling a random array value using PHP’s array_rand() function. What am I doing wrong?!
$topics = array("1", "2", "3");
$colors = array("#ff3333", "#ffcc00", "#ccff33");
foreach ($topics as $t) {
$c = array_rand($colors, 1);
echo "style='color:$c'";
}
I’m getting integers returned, rather than my values.
array_rand() returns the key for a random entry.
So you need to use
$colors[$c].Code: