brem13 Posted June 30, 2010 Share Posted June 30, 2010 hey, i'm trying to make a while loop that will make a var name go up by number, ie($pic1, $pic2, $pic3, etc) if the value isnt blank, however its not doing it the way i want, $i = 0; $count = 0; while($i<=5) { $i++; if($$pic.$i=="") $count++; }//end while Link to comment https://forums.phpfreaks.com/topic/206301-while-loop-for-var-name/ Share on other sites More sharing options...
salathe Posted June 30, 2010 Share Posted June 30, 2010 Why do you want to do that? It seems more appropriate that you would use an array to store a list of something. For what it's worth, you would use ${'pic'.$i} to access the numbered variables: see variable variables in the manual. Link to comment https://forums.phpfreaks.com/topic/206301-while-loop-for-var-name/#findComment-1079234 Share on other sites More sharing options...
kenrbnsn Posted June 30, 2010 Share Posted June 30, 2010 Try <?php $count = 0; for ($i=0;$i<6;++$i) { if (${'pic'.$i} != '') { $count++; } } echo $count; ?> Ken Link to comment https://forums.phpfreaks.com/topic/206301-while-loop-for-var-name/#findComment-1079235 Share on other sites More sharing options...
brem13 Posted June 30, 2010 Author Share Posted June 30, 2010 thank you, it worked ken Link to comment https://forums.phpfreaks.com/topic/206301-while-loop-for-var-name/#findComment-1079248 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.