Variables are used to store values, such as the results of numbers, strings, or functions, so that we can use them more than once in a script to store values, such as numbers, text strings, or arrays.
Once a variable is set, we can use it repeatedly in the script.
All variables in PHP start with the $ symbol.
PHP's code insertion is straightforward, " " ends.
All variables start with "$", such as "$money". (The definition is easy to imagine) need to use, define, you can omit the definition of the variable type, PHP compiler will automatically choose for us.
For conditional judgment statements, PHP and C are similar. if (condition a) {procedure A}, there is else and ElseIf. else used to run a procedure other than condition A, elseif (condition n ...) It is the code that runs when the other condition is true.
Here is the code you wrote:
| The code is as follows |
Copy Code |
|
if.php
$sex = $_post["Sex"];
if ($sex = = "Male")
{
echo "Male";
}
ElseIf ($sex = = "female")
{
echo "female";
}
Else
{
echo "Unknown gender";
}
?>
|
The meaning of the code is to post the gender option via the form, male and female, and then hand it over to PHP to receive the post data and pass it to the sex variable. The final judgment, if is male output male, female output female, other condition output unknown.
After submission
The if.php mentioned in this article can be tested here.
Then switch, which is also very well understood, similar to if and elseif combination, but encountered a lot of conditions need to judge, switch back to the code is very simple and intuitive.
PHP code
| The code is as follows |
Copy Code |
Switch (variable name)
{
Case value 1:
Code to is executed if expression = Label1;
Break
Case Value 2:
Code to is executed if expression = Label2;
Break
Default
Code to be executed
If expression is different
From both Label1 and Label2;
} |
When the value in the variable satisfies "value 1" or "Value 2", execute the code below two case respectively, and then remember to use "break" between each "case". Separate. Executes the code under "Default" when the value in the variable is neither "value 1" nor "Value 2".
http://www.bkjia.com/PHPjc/628688.html www.bkjia.com true http://www.bkjia.com/PHPjc/628688.html techarticle variables are used to store values, such as the results of numbers, strings, or functions, so that we can use them more than once in a script to store values such as numbers, text strings, or numbers ...