Reputation: 1647
I have an array like this:
[0] => Array
(
[slideritem] => 592
[sliderbig] => 644
)
[1] => Array
(
[slideritem] => 593
[sliderbig] => 645
)
[2] => Array
(
[slideritem] => 594
[sliderbig] => 646
)
slideritem is the id of an image that will be displayed and the slidebig is the image that will be linked to be displayed on a lightbox.
In other words i want the markup to be:
<a href="[sliderbig]"><img src="[slideritem]" /></a>
I pretty sure it's a simple foreach statement but i'm already on my 12th hour straight in front of the screen :)
Upvotes: 0
Views: 94
Reputation: 316969
Something like this?
foreach($theArray as $slider) {
printf('<a href="%d.png"><img src="%d.png" alt="sliderimage"/></a>',
$slider['sliderbig'],
$slider['slideritem']);
}
Take a break!
Upvotes: 0
Reputation: 97815
function test($accum, $a) {
return $accum . sprintf('<a href="url/to/%s">' .
'<img src="url/to/%s" /></a>'."\n",
htmlspecialchars($a['sliderbig']),
htmlspecialchars($a['sliderbigitem']));
}
$output = array_reduce($array, 'test', '');
Upvotes: 0
Reputation: 14654
foreach($array as $item) {
echo "<a href="{$item->sliderbig}"><img src="{$item->slideritem}" /></a>";
}
Upvotes: 1