PHP Chapter 2 Notes - process control

Process control:
Control the execution process of PHP program!
What means does PHP have to control the program process!
1, Sequential execution
It is executed from top to bottom. There is no control over this execution process!
2, Branch execution
Branch execution can choose to execute some code according to whether the conditions are met. PHP branch execution is mainly realized through two statements (if,switch)!
1.if statement
Note: the code controlled by the expression of the if statement is best enclosed in curly braces, even if a statement is enclosed in curly braces!
if statements can be nested according to actual requirements
1) Unidirectional condition
If (expression) statement 1;
If the value of the expression is true, statement 1 will be executed, otherwise it will not be executed!

        echo 'Congratulations, passed the exam!';
        echo 'dwetawet';
        //..... Various other statements!
        echo 'End of code execution';
    2)Bidirectional condition
        if ($a>=$pass){
            echo 'congratulations!Pass the exam!';
            echo 'unfortunately,Your subject failed';
    3)Multidirectional condition
        $grade1=60;//Fail below 60
        if ($a<$grade1){
            echo 'fail,';
        }elseif ($a<$grade2){
            echo 'You passed the children's shoes';
        }elseif ($a<$grade3){
            echo 'good!';
            echo 'excellent';
2.switch sentence
        case Value 1://case is equivalent to==
            Statement block 1;
        case Value 2:
            Statement block 2;
            Statement block n
        1)The value of an expression should preferably be an integer or a string!
        2)Don't forget it break sentence!Come and jump out switch sentence!each case Add after the statement break
        3)If one case If there is no statement block after the statement, it means that the content of this statement block is the same as the following!
        4)case The following statement block is not required{}Enclosed

3, Loop execution
One of the best functions of the computer is to repeat some operations according to the specified conditions, which is the program structure that can give full play to the computer's specialty in program design.
1.while statement
While (expression){
Various statements
When the value of the expression is true, the following statement block will be executed. After the execution of the statement block, continue to return to the above to judge whether the value of the expression is true or false. If it is true, then
Continue to execute until the value of the expression is false, and the execution of the while statement is over!
i = 0 ; w h i l e ( i=0; while ( i=0;while(i<10){
echo $i++.'
echo 'execution is over!'; while statement
Various statements
}While (expression);

    And while The difference is, do while Statement is executed at least once!
3.for sentence
    for(expression a;expression b;expression c){
        Various statements
    expression a:Some initialization statements will be put,$i=0,Put multiple expressions,Intermediate use,separate
    expression b:Will put some for judgment true perhaps false Expression for!,You can also put multiple expressions,Intermediate use,separate
    expression c:Some statements will be put to automatically increment the initialized variables

    expression a
    expression b If it is true
    Statement block
    expression c
    expression b

4, Special process control statement
1.break statement
Function: used for switch statements, for,while,do... while,foreach, used to interrupt these statements!
A number can be followed to indicate jumping out of several layers of circulation! The default is to jump out of the current circular statement!
2.continue statement
Function: it can only be used in circular statements. Jumping out of this cycle does not end the whole circular statement!
3.exit() statement
Function: end the execution of the current whole program!

Tags: PHP

Posted by davidjam on Wed, 11 May 2022 14:53:40 +0300