atticus Posted August 20, 2009 Share Posted August 20, 2009 Alright, so I declared the array...I put an initial value in the array. I am using a while loop to add each other element into the array <?php $img = array("<!--start of hidden images for quicker load time -->"); ?> <div class="preview"><a href="preview.php?number=<?php echo $number ?>" target="_blank"> <img src="http://www.domain.com/screenshots/<?php echo $number; ?>-m.jpg" alt="<?php echo $title; ?>" width="145" border="0" onmouseover="showtrail(250,250,'screenshots/<?php echo $number; ?>-b.jpg');" onmouseout="hidetrail();"/> <img class="button" border="0" title="preview" src="images/preview.png" alt="preview" width="88" height="22" /></a></div> <?php var_dump($img); $img[] = "<img src=\"http://www.domain.com/screenshots/".$number."-b.jpg\" class=\"hidden\" />"; } The output I am getting is only the first and last values in the array. The comment I added first, and the last run of the while loop: code to get it: foreach ($img as $b) { echo $b; } the output: <!--start of hidden images for quicker load time --><img src="http://www.domain.com/screenshots/24367-b.jpg" class="hidden" /> this is the result of a var dump: array(2) { [0]=> string(52) "<!--start of hidden images for quicker load time -->" [1]=> string(89) "<img src="http://www.websitestarterpackage.com/screenshots/24367-b.jpg" class="hidden" />" } Link to comment https://forums.phpfreaks.com/topic/171176-solved-adding-value-to-end-of-array-with-while-loophaving-problems/ Share on other sites More sharing options...
atticus Posted August 20, 2009 Author Share Posted August 20, 2009 There is something about this place...I posted the question that I was stumped on for like 30 minutes...and the answer is right there in front of me...I declared the array inside of the while loop. Thats what I get for working on this with 3 hours sleep for the last 10 hours. Thanks anyway Link to comment https://forums.phpfreaks.com/topic/171176-solved-adding-value-to-end-of-array-with-while-loophaving-problems/#findComment-902677 Share on other sites More sharing options...
genericnumber1 Posted August 20, 2009 Share Posted August 20, 2009 If all of that is encased in a while loop (you should have included it, btw) then it's because your redefining $img each time it loops, so it only exists after the last iteration of the loop. Move the $img definition outside of the loop and you should be fine. If that's not your problem, could you show us the full code including the loop and definition of these variables you are using? Nevermind, glad you got it working Link to comment https://forums.phpfreaks.com/topic/171176-solved-adding-value-to-end-of-array-with-while-loophaving-problems/#findComment-902679 Share on other sites More sharing options...
atticus Posted August 20, 2009 Author Share Posted August 20, 2009 thanks for the help though Link to comment https://forums.phpfreaks.com/topic/171176-solved-adding-value-to-end-of-array-with-while-loophaving-problems/#findComment-902682 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.