johnsmith153 Posted October 10, 2008 Share Posted October 10, 2008 Ok, Im gonna get called lazy, but I have looked on php.net I have been doing php for about 6 months. I can do foreach($array as $key >=$record) etc, but all I need is so it counts from 1 -10 for i = ++ or something, - easy I am sure if you know how. Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted October 10, 2008 Share Posted October 10, 2008 i am trying to remeber for($i=1, $i < 11, $i++) i think thats it Quote Link to comment Share on other sites More sharing options...
johnsmith153 Posted October 10, 2008 Author Share Posted October 10, 2008 for($i=1; $i < 11; $i++) ; not , - thanks, you got me started Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 10, 2008 Share Posted October 10, 2008 Or: <?php foreach (range(1, 10) as $num) { echo "$num<br />"; } ?> Quote Link to comment Share on other sites More sharing options...
Lamez Posted October 10, 2008 Share Posted October 10, 2008 you could use a while loop. Quote Link to comment Share on other sites More sharing options...
exally Posted October 10, 2008 Share Posted October 10, 2008 foreach blows for ftw. lolz Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 10, 2008 Share Posted October 10, 2008 SOMEONE SHOW ME THE SAME WITH DO WHILE LOOP PLEASE .... <?php //foreach method foreach(range(1, 10) as $redarrow){ echo $redarrow; } echo"<br><br>"; //for loop. for($i=1; $i<11; $i++){echo $i;} echo"<br><br>"; $x=1; while($x<11) {echo $x; $x++;} echo"<br><br>"; ?> Quote Link to comment Share on other sites More sharing options...
Lamez Posted October 10, 2008 Share Posted October 10, 2008 here is a simple while loop, took a noob like me, less than a minuet to write. <?php $start_num = 0; $max_num = 10; while($start_num < $max_num){ $start_num++; echo $start_num."<br>"; } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 10, 2008 Share Posted October 10, 2008 and that a do while loop yea Quote Link to comment Share on other sites More sharing options...
Lamez Posted October 10, 2008 Share Posted October 10, 2008 lol, seems like any loop would be appropriate. Just which one is easier\more efficient. Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 10, 2008 Share Posted October 10, 2008 i want to learn the same as u posted in a do while loop please Quote Link to comment Share on other sites More sharing options...
trq Posted October 10, 2008 Share Posted October 10, 2008 i want to learn the same as u posted in a do while loop please This is all covered (like everything else) in the manual. <?php $i = 0; do { echo $i . "<br />"; $i++; } while ($i < 11); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.