PHP - The if statement


SUBMITTED BY: KkK1337

DATE: June 27, 2017, 2:31 a.m.

FORMAT: PHP

SIZE: 482 Bytes

HITS: 704

  1. Example 1
  2. <?php
  3. $foo = 1;
  4. $bar = 2;
  5. if ($foo == $bar) {
  6. echo "$foo is equal to $bar.";
  7. } elseif ($foo > $bar) {
  8. echo "$foo is greater than $bar.";
  9. } else {
  10. echo "$foo is less than $bar.";
  11. }
  12. ?>
  13. Example 2
  14. <?php
  15. $lower = 10;
  16. $upper = 100;
  17. $needle = 25;
  18. if (($needle >= $lower) && ($needle <= $upper)) {
  19. echo "The needle is in the haystack.";
  20. } elseif (($needle <= $lower) || ($needle >= $upper)) {
  21. echo "The needle is outside of the haystack.";
  22. }
  23. ?>

comments powered by Disqus