Advertisement
karlakmkj

function with if-else condition

Sep 16th, 2021
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2. namespace Codecademy;
  3.  
  4. $learner_one = ["is_correct"=>FALSE, "box"=>["shape"=>"none", "color"=>"none"]];
  5.    
  6. $learner_two = ["is_correct"=>TRUE, "box"=>["shape"=>"none", "color"=>"none"]];
  7.  
  8. //function for arrays - make permanent changes to $box variable
  9.   function markAnswer($is_answer_correct, &$box){
  10.     if ($is_answer_correct){
  11.       $box["shape"] = "checkmark";
  12.       $box["color"] = "green";
  13.     } else {
  14.       $box["shape"] = "x";
  15.       $box["color"] = "red";
  16.     }
  17.   }
  18. markAnswer($learner_one["is_correct"], $learner_one["box"]);
  19. markAnswer($learner_two["is_correct"], $learner_two["box"]);
  20. print_r($learner_one["box"]);
  21. print_r($learner_two["box"]);
  22.  
  23.  
  24. function chooseCheckoutLane($items) {
  25.   if ($items <=12) {
  26.     return "express lane";
  27.   }
  28.   else {
  29.     return "regular lane";
  30.   }
  31. }
  32.  
  33. function canIVote($age){
  34.   if ($age>=18){
  35.     return "yes";
  36.   } else {
  37.     return "no";
  38.   }
  39. }
  40.  
  41. // test for each condition
  42. echo chooseCheckoutLane(20);
  43. echo chooseCheckoutLane(5);
  44. echo canIVote(30);
  45. echo canIVote(16);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement