How-the-else-if-works - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of How-the-else-if-works.php

  1. <?php
  2. if (true) { 
  3.         echo "only first" . PHP_EOL;
  4. } elseif (true) { 
  5.         echo "---"; 
  6. } elseif (true) {
  7.         echo "---"; 
  8. }
  9.  
  10. if (false) { 
  11.         echo "---";
  12. } elseif (false) { 
  13.         echo "---"; 
  14. } elseif (true) {
  15.         echo "only last" . PHP_EOL; 
  16. }
  17.  
  18.  
  19. if (var_dump("check 1") || false) { 
  20.         echo "---";
  21. } elseif (var_dump("check 2") ||  false) { 
  22.         echo "---"; 
  23. } elseif (var_dump("check 3") ||  false) {
  24.         echo "---";
  25. } elseif (var_dump("check 4 and goes in") || true) {
  26.         echo "In the last case" . PHP_EOL; 
  27. }
File Description
  • How-the-else-if-works
  • PHP Code
  • 31 Aug-2022
  • 485 Bytes
You can Share it: