Jump to content

indexOf(0)...


you_n_me_n_php

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.