Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Nested Conditional Statements
- function both($first, $second)
- {
- if ($first){
- if ($second){
- return "both";
- } else {
- return "not both";
- }
- } else {
- return "not both";
- }
- }
- echo both(TRUE, TRUE);
- echo "\n\n";
- echo both(FALSE, FALSE);
- echo "\n\n";
- echo both(TRUE, FALSE);
- // The || Operator
- function willWeEat($meal_type, $is_hungry){
- if ($meal_type === "dessert" || $is_hungry){
- return "Yum. Thanks!";
- } else {
- return "No thanks. We're not hungry.";
- }
- }
- echo willWeEat("dessert", false);
- echo "\n\n";
- echo willWeEat("dinner", false);
- // The && Operator
- function clapYourHands($is_happy, $knows_it){
- if ($is_happy && $knows_it){
- return "CLAP!";
- } else {
- return ":(";
- }
- }
- echo clapYourHands(TRUE, TRUE);
- echo "\n\n";
- echo clapYourHands(TRUE, FALSE);
- // The Not Operator
- function duckDuckGoose($is_goose){
- if (!$is_goose){
- return "duck";
- } else {
- return "goose!";
- }
- }
- echo duckDuckGoose(FALSE);
- echo "\n";
- echo duckDuckGoose(FALSE);
- echo "\n";
- echo duckDuckGoose(TRUE);
- // The Xor Operator
- function eatPie($ingredients){
- if (in_array("chicken", $ingredients) xor in_array("bananas", $ingredients)){
- return "Delicious pie!";
- } else {
- return "Disgusting!";
- }
- }
- echo eatPie($banana_cream);
- echo "\n\n";
- echo eatPie($experimental_pie);
- // Alternative
- $is_admin = FALSE;
- $is_user = TRUE;
- if ($is_admin or $is_user){
- echo "You can change the password.\n";
- }
- $correct_pin = TRUE;
- $sufficient_funds = TRUE;
- if ($correct_pin and $sufficient_funds){
- echo "You can make the withdrawal.";
- }
- // Includes
- include "top_bread.php";
- include "mayo.php";
- include "lettuce.php";
- echo "Sliced, ripe tomatoes\nBacon\nTurkey\n";
- include "bottom_bread.php";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement