I cant seem to echo the values inside my foreach array, my code so far.
<?php
foreach ($results as $item) {
$imgData = json_decode($item->params, true);
// create array
$newsitems[] = array(
'name' => $item->name,
'url' => $item->clickurl,
'custom' => $item->custombannercode,
'image' => $imgData['imageurl']
);
}
?>
<?php foreach ($newsitems as $slideitems) { ?>
<li>
<img src="<?php echo $slideitems->image; ?>" >
</li>
<?php }; ?>
I get two list items which is correct but when i try to echo out any values it shows blank, am I doing this correct?
Thanks
<?php foreach ($newsitems as $slideitems) {
var_dump($slideitems); ?>
<li>
<img src="<?php echo $slideitems['image']; ?>" >
</li>
<?php }; ?>
You could try a var_dump to see what values you're getting. Also as slideitems is an array check the line that outputs the img src.
I hope this helps.
$newsitems[] = array( ... )
therefore you need
<?php echo $slideitems['image']
in your ourput loop.
$slideitems
is an array
not object So,
Change
<?php echo $slideitems->image; ?>
to
<?php echo $slideitems['image']; ?>
In the first loop you assign array
$newsitems[] = array(
but here
$slideitems->image
you're referencing to object. consider using $slideitems['image']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With