Home >Backend Development >PHP Tutorial >PHP output odd and even numbers example

PHP output odd and even numbers example

WBOY
WBOYOriginal
2016-07-25 09:13:233761browse

Example 1, php outputs odd numbers:

  1. for ($i=0;$i<=10;$i++)
  2. {
  3. if ($i%2 == 0)
  4. {
  5. echo $i;
  6. echo "
    ";
  7. }
  8. }
  9. ?>
Copy code

Example 2, PHP outputs even numbers:

  1. for ($i=0;$i<=10;$i++)
  2. {
  3. if ($i%2 != 0)
  4. {
  5. echo $i;
  6. echo "
    ";
  7. }
  8. }
  9. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn