canViewMovie function - 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 canViewMovie function.php

  1. <?php
  2. function canViewMovie($age, $balance, $price){
  3.     if ($age >= 18 && $balance >= $price){
  4.         return "Let's view the movie!";
  5.     }
  6.     elseif($age >= 18 && ($balance < $price)){
  7.         return "Damn, better earn some more money.";
  8.     }
  9.     else {
  10.         return "Looks like we're not old enough to get into that movie...";
  11.     }
  12. }
  13.  
  14. $age1 = 18;
  15. $balance1 = 13;
  16. $price1 = 10;
  17.  
  18. $age2 = 15;
  19. $balance2 = 50;
  20. $price2 = 12;
  21.  
  22. $age3 = 25;
  23. $balance3 = 4;
  24. $price3 = 11;
  25.  
  26. echo canViewMovie($age1, $balance1, $price1) . "\n";
  27. echo canViewMovie($age2, $balance2, $price2) . "\n";
  28. echo canViewMovie($age3, $balance3, $price3) . "\n";
File Description
  • canViewMovie function
  • PHP Code
  • 24 May-2020
  • 630 Bytes
You can Share it: