Jump to content

php foreach array (counting and assigning id to each row)


phantomlimb

Recommended Posts

I'm doing some work with PHP, and Flickr.

 

I have an array of photos. The photos are contained in divs. I want to give the div an ID based on the result number. I don't really know where to start with this piece, hoping to get some advice from the more experienced coders amongst us.

 

I assume i will have to count the number of the results in the array and dynamically assign the div id a number eg. the first result <div id="panel1">, the second result <div id ="panel2">.

 

 

here is the piece of code i am working with, any help appreciated:

 

<? foreach ((array)$photos_norway['photo'] as $phototagged) : ?>

<div id="panel1">

<img src="<?= $f->buildPhotoURL($phototagged, 'medium') ?>" />

</div>

<?php endforeach; ?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.