Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. //Nested Conditional Statements
  2.  
  3. function both($first, $second)
  4. {
  5. if ($first){
  6. if ($second){
  7. return "both";
  8. } else {
  9. return "not both";
  10. }
  11. } else {
  12. return "not both";
  13. }
  14. }
  15.  
  16. echo both(TRUE, TRUE);
  17. echo "\n\n";
  18. echo both(FALSE, FALSE);
  19. echo "\n\n";
  20. echo both(TRUE, FALSE);
  21.  
  22. // The || Operator
  23.  
  24. function willWeEat($meal_type, $is_hungry){
  25. if ($meal_type === "dessert" || $is_hungry){
  26. return "Yum. Thanks!";
  27. } else {
  28. return "No thanks. We're not hungry.";
  29. }
  30. }
  31. echo willWeEat("dessert", false);
  32. echo "\n\n";
  33. echo willWeEat("dinner", false);
  34.  
  35. // The && Operator
  36.  
  37. function clapYourHands($is_happy, $knows_it){
  38. if ($is_happy && $knows_it){
  39. return "CLAP!";
  40. } else {
  41. return ":(";
  42. }
  43. }
  44. echo clapYourHands(TRUE, TRUE);
  45. echo "\n\n";
  46. echo clapYourHands(TRUE, FALSE);
  47.  
  48. // The Not Operator
  49.  
  50. function duckDuckGoose($is_goose){
  51. if (!$is_goose){
  52. return "duck";
  53. } else {
  54. return "goose!";
  55. }
  56. }
  57. echo duckDuckGoose(FALSE);
  58. echo "\n";
  59. echo duckDuckGoose(FALSE);
  60. echo "\n";
  61. echo duckDuckGoose(TRUE);
  62.  
  63. // The Xor Operator
  64.  
  65. function eatPie($ingredients){
  66. if (in_array("chicken", $ingredients) xor in_array("bananas", $ingredients)){
  67. return "Delicious pie!";
  68. } else {
  69. return "Disgusting!";
  70. }
  71. }
  72.  
  73. echo eatPie($banana_cream);
  74. echo "\n\n";
  75. echo eatPie($experimental_pie);
  76.  
  77. // Alternative
  78.  
  79. $is_admin = FALSE;
  80. $is_user = TRUE;
  81. if ($is_admin or $is_user){
  82. echo "You can change the password.\n";
  83. }
  84.  
  85.  
  86. $correct_pin = TRUE;
  87. $sufficient_funds = TRUE;
  88. if ($correct_pin and $sufficient_funds){
  89. echo "You can make the withdrawal.";
  90. }
  91.  
  92. // Includes
  93.  
  94. include "top_bread.php";
  95. include "mayo.php";
  96. include "lettuce.php";
  97.  
  98. echo "Sliced, ripe tomatoes\nBacon\nTurkey\n";
  99.  
  100. include "bottom_bread.php";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement