using foreach loop within html

I have 2 dynamic arrays with variable number of strings that is a conditional
selection from a mysql database using php php
Both arrays will have the same number of strings.
Example $imagearray[0] = “images/large/5.jpg”
$imagearray[1] = “images/large/3.jpg”
$imagearray[2] = “images/large/8.jpg”
…and so on
$thumbarray[0] = "images/thumbs/5.jpg
$thumbarray[1] = “images/thumbs/3.jpg”
$thumbarray[2] = “images/thumbs/8.jpg”
…and so on

The html-php code looks like this:

<?php foreach ($proarray as $large):?>
<span id="<?=$large['pro_id'];?>"> <img src="<?=$large['proimage']?>" /></span>
<?php endforeach;?>

This works and I get the following html code

<div id="large" ....and so on For the thumbnails i want the following
....and so on

you will notice the first thumbs <a href line has a class, the rest don’t
I want to use a php foreach statement
and want to check if its the first image in the array
here is my code that doesn’t work

			<div id="thumbs">									
				<?php $i=0;?>
				<?phpforeach ($thumbarray as $thumb):?>

` <?phpif ($i == 0)?>

<?php if ($i!= 0) ?>

<?php endforeach;?>

It looks like your code should work, unless there is a syntax error? I noticed a backtick in there but wasn’t sure if that’s from posting.

You should be able to just use the array index. For example:


<?php foreach($thumbarray as $key => $thumb):?> > <?php endforeach;?>

Where $key is the array index

Sponsor our Newsletter | Privacy Policy | Terms of Service