Posted By

stephcode on 05/14/11


Tagged

php if else


Versions (?)

Basic if and else if statement with PHP


 / Published in: PHP
 

  1. if:
  2.  
  3. <?php if ($foo == 'yes') { ?>
  4. do something
  5. <?php } if ($bar == 'no') { ?>
  6. do something else
  7. <?php } ?>
  8.  
  9.  
  10. else/if:
  11.  
  12. <?php if ($foo == 'surething') { ?>
  13. do this
  14. <?php } else { ?>
  15. do everything else
  16. <?php } ?>
  17.  
  18. else/if variation:
  19.  
  20. <a class="<?php if ($foo == 'righto') { ?>
  21. selected
  22. <?php } else { ?>
  23. hoverBtn
  24. <?php } ?>" href="contact.php"><span>Contact</span></a>

Report this snippet  

You need to login to post a comment.