Advertisement
karlakmkj

function - true, false

Sep 17th, 2021
882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | None | 0 0
  1. <?php
  2. namespace Codecademy;
  3.  
  4. // Basic function for true or false condition
  5. function truthyOrFalsy($val){
  6.   if ($val){
  7.     return "True";
  8.   } else {
  9.     return "False";
  10.   }
  11. }
  12.  
  13. echo truthyOrFalsy(2);
  14. echo "\n\n";
  15. echo truthyOrFalsy(null);
  16.  
  17. // using readable 'or' 'and' operators
  18. $is_admin = FALSE;
  19. $is_user = TRUE;
  20. if ($is_admin or $is_user){  //can also use ||
  21.   echo "You can change the password.\n";
  22. }
  23.  
  24. $correct_pin = TRUE;
  25. $sufficient_funds = TRUE;
  26. if ($correct_pin and $sufficient_funds){  // or use &&
  27.   echo "You can make the withdrawal.";
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement