Variables are used to store values, such as numbers, strings, or function results, so that we can use them multiple times in the script to store values, such as numbers, text strings, or arrays once set
Variables are used to store values, such as numbers, strings, or function results, so that we can use them multiple times in the script to store values, such as numbers, text strings, or arrays.
Once a variable is set, we can re-use it in the script. all variables in PHP start with the $ symbol.
PHP code insertion is intuitive ," "End.
All variables start with "$", for example, "$ money ". (definition operators are easy to imagine.) when you need to use them, you can 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 code is as follows:
-
-
- $ Sex = $ _ POST ["sex"];
- If ($ sex = "male ")
- {
- Echo "male ";
- }
- Elseif ($ sex = "female ")
- {
- Echo "female ";
- }
- Else
- {
- Echo "unknown gender ";
- }
- ?>
The code means to submit gender options in form. Final Judgment: male outputs male, female outputs female, and unknown output in other cases.
If. php can be tested here, and then switch. this is also 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.
The code is as follows:
- Switch (variable name)
- {
- Case value 1:
- Code to be executed if e-xpression = label1;
- Break;
- Case value 2:
- Code to be executed if e-xpression = label2;
- Break;
- Default:
- Code to be executed
- If e-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.