PHP Learning Notes variable usage detailed _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.