Once a variable is set, we can reuse it in the script.
All variables in PHP start with the $ symbol.
PHP code insertion is intuitive, "<? Php "start"?> "End.
All variables start with "$", for example, "$ money ". (Definition operators are easy to imagine.) when you need to use them, define them. You can omit the definition of the variable type. The php compiler will automatically choose for us.
For condition judgment statements, php and c are similar. If (condition A) {process A}, there are else and elseif. Else is used to run A process other than condition A. elseif (condition N...) is the code that runs when other conditions are true.
The following code is written by myself:
| The code is as follows: |
Copy code |
If. php <Html> <Body> <Center> <Form action = "if. php" method = "post"> <Input type = "radio" name = "sex" value = "male"/> male </Br> <Input type = "radio" name = "sex" value = "female"/> female </Br> <Input type = "submit" value = "submit"/> </Form> <? Php $ Sex = $ _ POST ["sex"]; If ($ sex = "male ") { Echo "male "; } Elseif ($ sex = "female ") { Echo "female "; } Else { Echo "unknown gender "; } ?> </Center> </Body> </Html> |
The code means to submit gender options in form. Final Judgment: male outputs male, female outputs female, and unknown output in other cases.
After submission
If. php mentioned in this article can be tested here
Then there is the switch, which is easy to understand. Similar to the combination of if and elseif, the switch back code becomes concise and intuitive when many conditions need to be judged.
PHP code
| The code is as follows: |
Copy code |
Switch (variable name) { Case value 1: Code to be executed if e & shy; xpression = label1; Break; Case value 2: Code to be executed if e & shy; xpression = label2; Break; Default: Code to be executed If e & shy; xpression is different From both label1 and label2; } |
When the values in the variable meet "value 1" or "value 2", execute the code under two cases respectively, and then remember that each "case" must be separated by "break. When the value in the variable is neither "value 1" nor "value 2", execute the code below "default.