2

Hi I am trying to get images to load into a page using the file names from an array,

This is what I have so far

<?php
$i=0;
$img=array("1.png","2.png","3.png","4.png");
while ($i<count($img))
{
echo "<img class='loadin' alt='imgg' src=" . "'http://www/images/" . $img[i] . "'" . "/" . ">" . "<br/>";
$i++;
}
?>

It seems to ignore the file name and just enters:

http://www/images/

as the source and ignores the file name from the array

Any Help would be great Thanks

Mikey

2
  • 1
    What's wrong exactly? And crazy concatenation can lead to crazy output. Commented Jan 15, 2013 at 15:46
  • That would be good to add wouldn't it lol Commented Jan 15, 2013 at 15:47

1 Answer 1

3

You forgot the dollar sign with your $i variable: $img[$i]

EDIT: (btw. using a foreach-loop would be easier...)

foreach($img AS $filename) {
    echo "<img class='loadin' alt='imgg' src='http://www/images/" . $filename . "'/><br/>";
}
Sign up to request clarification or add additional context in comments.

1 Comment

foreach is one of my favorite parts of PHP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.