Usage of variables in PHP learning Notes

Source: Internet
Author: User

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.

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.