you_n_me_n_php Posted June 18, 2010 Share Posted June 18, 2010 Hi everyone, I'm new to php. I want to put in a line break after the echoed count value if it has a "0" in it (i.e. 20<br />,30 <br/>, etc.) Is strrpos the right function to use? Does php have an IndexOf() function? <?php $count = 0; $pos = strrpos($count, "0"); while($count <=4000) { echo $count; $count++; if ($pos ==true) { echo "<br />"; } } ?> Thanks!!! Link to comment https://forums.phpfreaks.com/topic/205135-indexof0/ Share on other sites More sharing options...
kenrbnsn Posted June 18, 2010 Share Posted June 18, 2010 Use the Modulus operator "%" <?php for ($i=0;$i<4000;++$i) { echo $i . ' '; if ($i % 10 == 0 && $i != 0) { echo "<br />\n"; } } ?> Ken Link to comment https://forums.phpfreaks.com/topic/205135-indexof0/#findComment-1073746 Share on other sites More sharing options...
Pikachu2000 Posted June 18, 2010 Share Posted June 18, 2010 Assuming you mean you want to echo it if the $count variable is a multiple of 10, you can use the modulus operator. <?php $count = 0; while($count <=4000) { echo $count . ", "; // Added the if{} conditional // if( $count % 10 == 0 && $count != 0) { echo "<br />"; } $count++; } ?> Link to comment https://forums.phpfreaks.com/topic/205135-indexof0/#findComment-1073747 Share on other sites More sharing options...
Pikachu2000 Posted June 18, 2010 Share Posted June 18, 2010 Hmph. Ya beat me to it . . . Oh well, at least great minds still think alike Link to comment https://forums.phpfreaks.com/topic/205135-indexof0/#findComment-1073748 Share on other sites More sharing options...
you_n_me_n_php Posted June 18, 2010 Author Share Posted June 18, 2010 Okay (and I ain't just kissing butt here, either). But DUUUUDE!!! Are you guys some FREAKS or what??? It couldn't have taken either of you more than 2 mins to write that code (if that). Mother of God! Look, I just registered as a new use 30 minutes ago. I have been in other communities before, but... Well, anyway... I have just set my home page to phpfreaks. Thank you, very kindly! Link to comment https://forums.phpfreaks.com/topic/205135-indexof0/#findComment-1073752 Share on other sites More sharing options...
kenrbnsn Posted June 18, 2010 Share Posted June 18, 2010 Yes, we're PHP Freaks. That's why we're on this forum... Ken Link to comment https://forums.phpfreaks.com/topic/205135-indexof0/#findComment-1073753 Share on other sites More sharing options...
you_n_me_n_php Posted June 18, 2010 Author Share Posted June 18, 2010 Ken, Well, I just found home. This page will stay up all the time. Thank you, again (both of you), for your kindness and expertise. Roland Link to comment https://forums.phpfreaks.com/topic/205135-indexof0/#findComment-1073756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.