PHP Learning Process Control implementation code

Source: Internet
Author: User
The code is as follows:

<?php/* * Process Control * * One, sequential structure * Two, branch structure--Conditional structure--Select structure * 1. Single Branch *//condition bool,true or false,> < = = | | | ! * IF (condition) * Executes the following statement * if (condition) * {* code snippet; * Code snippet; *} * * 2. Dual Branch * Use ELSE clause * * IF (condition) * Execute a statement * else * Execute a statement * if (condition) {*  Bar or multiple code *}else{* One or more codes *} * 3. Multi-Branch * can use if else if and switch case *//This is a mutually exclusive relationship * if (condition) {* * *}else if (condition) {*}else if (condition) {*}else{*} * 4. Nested branch * if () {* if () {*}else{* if () {} *} *} * Three, loop structure * * * * * * * Summary: * If you are judging a range then use the ElseIf * If it is a single match, use the switch case *////single-path execution $a = 10; $b = 5; if ($a > $b) echo "$a is greater than $b"; Two-way execution $a = 10; $b = 20; if ($a > $b) {echo "$a greater than $b </br>";} else {echo "$a less than $b </br>";}//Multi-route execution $hour =date ("H"); if ($hour > 6 && $hour < 9) {echo "Good morning!":} else if ($hour > 9 && $hour <) {echo] Good Morning "; } else if ($hour > && $hour <) {echo "Good noon";} else if ($hour > && $hour <) {echo] Good afternoon "; } else if ($hour > && $hour <) {echo "Good evening""; } else if ($hour > && $hour <22) {echo "Good evening"} else {echo "Good Night"}//improved code based on mutex $hour =date ("H"); if ($hour < 9) {echo "Good morning!":} else if ($hour <) {echo "Good Morning";} else if ($hour <) {echo case "Mon ": Echo" Monday "; break; " Good noon "; } else if ($hour <) {echo "Good afternoon"} else if ($hour >) {echo "Good evening";} else if ($hour <) {echo "Good Evening"} Els e {echo "Good Night"}//Judgment Day of the week $week =date ("D");//Get Days of the week switch ($week)//switch (variable) variable only with integer and string {case "Mon": echo "Monday"; Case "Tue" echo "Tuesday"; Break Case "Wed": echo "Wednesday"; Break Case "Thu": echo "Thursday"; Break Case "Fri": echo "Friday"; Break Default:echo "Weekend"; }//Nested class $sex =$_get["sex"]; $age =$_get["age"]; if ($sex = = "Nan") {if ($age >=) {echo "This $sex has retired". $age-60). " Years "; } else {echo "This man is still working, and". ( 60-$age). " Years of retirement "; }} else {if ($age >=) {echo "This $sex has retired". $age-66). " Years "; } else {echo "This lady is still working, and". ( 66-$age). " Years of retirement "; }}?>
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.