I. Condition Statement 1. if statement syntax: if (condition statement 1) for example $ a $ B or $ a & gt; $ B {command executed when Condition Statement 1 is met, such as echo & quot; a is greater than B & quot;} elseif (condition statement 2) for example, $ a & lt; 0 or $ B & lt; 0 {command executed when condition statement 2 is met, for example, echo & quot; because a or...
I. Condition Statement
1. if statement syntax:
If (condition 1) for example $ a = $ B or $ a> $ B
{
Command executed when Condition 1 is met, such as echo "a is greater than B ";
}
Elseif (condition statement 2) for example, $ a <0 or $ B <0
{
Command executed when condition 2 is met, such as echo "because a or B is less than 0, beyond the optional range ";
}
Else does not need to be connected. the meaning of the branch is that when neither condition 1 nor condition 2 is met
{
Executed when neither condition 1 nor condition 2 is met. for example, echo "Your input is empty. please enter again ";
}
$ B) {echo "a> B";} elseif ($ a <$ B) {echo" Output result a> B
Instance 2
= 60 & $ secore <70) {echo "your score has passed";} elseif ($ secore >=70 & $ secore <80) {echo "your score is good";} elseif ($ secore >=80 & $ secore <90) {echo "your score is good ";} elseif ($ secore >=90 & $ secore <= 100) {echo "your excellent score";} elseif ($ secore> 100 | $ secore <0) {echo "the score you entered is invalid";} else {echo "your score failed. please continue to work." ;}?> Output result: Your score is excellent.
(2) switch statement syntax
Switch (condition variable) for example: $
{
Case condition variable conditions such as $ a> 0: executed when the conditions are met, such as echo a> 0; break;
Case condition variable conditions such as $ a <0: executed when the condition is met, such as echo a <0; break;
Default: output when none of the preceding conditions are met. for example, echo "a and B are invalid ";
}
= 60 & $ secore <70: $ pj = "your score has passed"; break; case $ secore> = 70 & $ secore <80: $ pj = "your score is good"; break; case $ secore >=80 & $ secore <90: $ pj = "your score is good"; break; case $ secore> = 90 & $ secore <= 100: $ pj = "your excellent performance"; break; case $ secore <0 | $ secore> 100: $ pj = "your score is invalid"; break; default: $ pj = "your score Fails. continue to work." ;}echo $ pj;?> Output result: Your score is excellent.
(3) operator syntax
Echo (condition, for example: $ a> $ B )? If the condition is true, the statement "a> B": if the condition is not true,"
$ B )? "A> B":" II. Process control statement
Loop statement
1. for statement syntax
For ($ variable name = 0; $ array name
{
Echo $ array name [$ variable name];
}
Output result: Zhang Chao, Qiao Bin, Chen Wei, Zhao Yongfeng
2. while statement syntax
$ Variable name = 0
While ($ variable name
{
Echo $ array name [$ variable name];
$ Variable name ++
}
Output result: Zhang Chao, Qiao Bin, Chen Wei, Zhao Yongfeng
3. foreach loop syntax
Foreach ($ variable name as $ variable rename)
{
Echo $ variable rename;
}
Output result: Zhang Chao, Qiao Bin, Chen Wei, Zhao Yongfeng
This article is from the "PHP study notes" blog