3.php Process Control

Source: Internet
Author: User
Tags case statement

Process Control:
Control the process of PHP program execution!
What are the means of PHP to control the process of program execution!
First, sequential execution
Top-down execution! There is no control over this execution process!
Second, branch execution
Branch execution can choose to execute some code depending on whether the condition is satisfied, and the branch execution of PHP is mainly implemented by two statements (If,switch)!
1.if statements
Note: The code that is controlled by the expression of our if statement is best enclosed in curly braces, even if a statement is enclosed in curly braces!
If statements can be nested, this is based on actual needs!
1) One-way condition
An if (expression) statement 1;
The value of the expression is true then EXECUTE statement 1, otherwise it will not execute!
$pass = 60;
$a = 40;
if ($a >= $pass) {
echo ' Congratulations, exam pass ';
Echo ' DWQDWQDQ ';
//....... Various other statements!
}
Echo ' Code execution is over! ‘;
2) bidirectional condition
$pass = 60;
$a = 40;
if ($a >= $pass) {
Echo ' Congratulations! Pass the exam! ‘;
//.......
}else{
Echo ' Sorry, your subject didn't pass! ‘;
//.......
}
3) Multi-directional conditions
$a = 84;
$grade 1=60;//less than 60 failed
$grade 2=75;//Pass.
$grade 3=85;//Good
if ($a < $grade 1) {
Echo ' failed ';
}elseif ($a < $grade 2) {
echo ' Children's shoes you passed ';
}elseif ($a < $grade 3) {
Echo ' Good! ‘;
}else{
echo ' excellent ';
}
2.switch statements
switch (expression) {
Case value 1://case equals = =
Statement Block 1;
Break
Case Value 2:
Statement Block 2;
Break
.......
Default
Statement block N
}

Note the point:
1) The value of an expression is best shaped or string!
2) Don't forget the break statement! To jump out of the switch statement! After each case statement, a break is added
3) If a case statement is not followed by a block of statements, then it means that the contents of this statement block are the same!
4) the statement block following the case does not need to be enclosed in {}

<?PHP$a=1;Switch($a){     Case1://Case equals = =     Case2: Case3:Echo' Today Wednesday <br/> '; Echo' DWQDWQDWQDWQDQ ';  Break;  Case4:Echo' Today Thursday <br/> ';  Break;//jump out, break the meaning!     Case5:Echo' Today Friday <br/> ';  Break;  Case6:Echo' Today Saturday <br/> ';  Break;  Case7:Echo' Today Sunday <br/> ';  Break; default:Echo' Numbers don't match up, don't know today is the day of the week!<br/> ';}Echo' Execution is complete! ‘;





3.php Process Control

Related Article

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.