• 0

[PHP] Alternate 3 numbers


Question

1 answer to this question

Recommended Posts

  • 0
I'm trying to create this :

012012012012012

I know I can use something like this:

if(($m & 1) == "1"){ 
 echo "1"; 
} else { 
 echo "0"; 
}

for 2 numbers, but how could I do 3?

Thanks!

while ($i <= 5) {

  $m = 0;
  if ($m++ == "1") {
	echo "0";
  } else if ($m++ == "2") {
	echo "1";
  }  else {
	echo "2"
  }

  $i++;
}

This will loop though the if conditionals 5 times ($i), and each time setting $m as 0 before it processes it. This will give you the output exactly how you wanted.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.