I am looking to loop through the array below and then populate a <UL>
with 1 random image from each color array. I am having trouble getting my head around how to access the specific color arrays... Do I need a loop? Or would array_rand()
be enough? How would I go about this?
$colors = array(
'green' => array(
'images/green1.jpg',
'images/green2.jpg',
'images/green3.jpg',
'images/green4.jpg',
'images/green5.jpg'
),
'red' => array(
'/images/red1.jpg',
'/images/red2.jpg',
'/images/red3.jpg',
'/images/red4.jpg',
'/images/red5.jpg'
),
'blue' => array(
'/images/blue1.jpg',
'/images/blue2.jpg',
'/images/blue3.jpg',
'/images/blue4.jpg',
'/images/blue5.jpg'
),
'purple' => array(
'/images/purple1.jpg',
'/images/purple2.jpg',
'/images/purple3.jpg',
'/images/purple4.jpg',
'/images/purple5.jpg'
)
);
<div>
<span>Colors</span>
<ul>
<li>"1 img from 'green' array would go here"</li>
<li>"1 img from 'red' array would go here"</li>
<li>"1 img from 'blue' array would go here"</li>
<li>"1 img from 'purple' array would go here"</li>
</ul>
</div>