Reputation: 23161
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.
Upvotes: 0
Views: 623
Reputation: 160833
array_rand() returns the key for a random entry.
So you need to use $colors[$c]
.
Code:
echo "style='color:$colors[$c]'";
Upvotes: 3