Advertisement
karlakmkj

Tenary operator

Sep 17th, 2021
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.37 KB | None | 0 0
  1. <?php
  2. namespace Codecademy;
  3.  
  4. // tenary operator to replace if-else stm
  5. function ternaryCheckout($item){
  6.   return $item <= 12 ? "express lane" : "regular lane";
  7. }
  8.  
  9. function ternaryVote($age){
  10.   return $age >=18 ? "yes" : "no";
  11. }
  12.  
  13.  
  14. echo ternaryCheckout(30);
  15. echo "\n";
  16. echo ternaryCheckout(1);
  17. echo "\n";
  18. echo ternaryVote(18);
  19. echo "\n";
  20. echo ternaryVote(5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement