Photoshop Learning Tutorial PHP Learning Flow Control Implementation code

Source: Internet
Author: User
Tags switch case
Copy CodeThe code is as follows:


/*
* Process Control
*
* First, sequential structure
* Two, branch structure--Conditional structure--Select structure
* 1. Single-channel branch
*//conditions bool,true or false,> < = =-& | | !
* IF (condition)
* Execute the following statement
* IF (condition)
* {
* Code snippet;
* Code snippet;
* }
*
* 2. Two-Way Branch
* Use ELSE clause
*
* IF (condition)
* Execute a statement
* Else
* Execute a statement
* if (condition) {
* One or more codes
*}else{
* One or more codes
* }
*
* 3. Multi-Channel Branch
* You can use if else if and switch case
*//This is a mutually exclusive relationship
* if (condition) {
*
*}else if (condition) {
*}else if (condition) {
*}else{
* }
* 4. Nesting branches
* if () {
* if () {
*}else{
* if () {}
* }
* }
* Three, Cycle structure
*
*
*
*
*
Summary
* If you are judging a range then use ElseIf
* If it is a single match, use the switch case
*/
Single-Channel 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
";
}
Else
{
echo "$a less than $b
";
}
Multi-Channel execution
$hour =date ("H");
if ($hour > 6 && $hour < 9)
{
echo "Good morning!":
}
else if ($hour > 9 && $hour < 12)
{
echo "Good Morning";
}
else if ($hour > && $hour < 14)
{
echo "Good Afternoon";
}
else if ($hour > && $hour < 17)
{
echo "Good Afternoon";
}
else if ($hour > && $hour < 19)
{
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 < 12)
{
echo "Good Morning";
}
else if ($hour < 14)
{
echo Case "Mon":
echo "Monday";
break; " Good noon ";
}
else if ($hour < 17)
{
echo "Good Afternoon";
}
else if ($hour > 19)
{
echo "Good evening";
}
else if ($hour < 22)
{
echo "Good evening";
}
Else
{
echo "Good Night";
}
Judging the day of the week
$week =date ("D");//Get the day of the week
Switch ($week)//switch (variable) variable only with integral type and string
{
Case "Mon":
echo "Monday";
Break
Case "Tue"
echo "Tuesday";
Break
Case "Wed":
echo "Wednesday";
Break
Case "Thu":
echo "Thursday";
Break
Case "Fri":
echo "Friday";
Break
Default
echo "Weekend";
}
Nested classes
$sex =$_get["Sex"];
$age =$_get["age"];
if ($sex = = "Nan")
{
if ($age >= 60)
{
echo "This $sex has retired". ($age-60). " Years ";
}
Else
{
echo "This man is still working, and." (60-$age). " Years of retirement ";
}
}
Else
{
if ($age >= 66)
{
echo "This $sex has retired". ($age-66). " Years ";
}
Else
{
echo "This lady is still working, and." (66-$age). " Years of retirement ";
}
}
?>

The above describes the Photoshop Learning Tutorial PHP learning Process Control implementation code, including the Photoshop Learning tutorial content, I hope to be interested in PHP tutorial friends helpful.

  • 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.