PHP basic syntax 002 variable

Source: Internet
Author: User
Tags php compiler uppercase letter
Variable variables in PHP are used to store values, such as numbers, text strings, or arrays. Once a variable is set, we can reuse it in the script. All variables in PHP start with the $ symbol, and the variable names are case sensitive. The correct way to set variables in PHP is: $ var_name = value; the PHP compiler often uses the variables in PHP.

Variables are used to store values, such as numbers, text strings, or arrays.

Once a variable is set, we can reuse it in the script.

All variables in PHP start with the $ symbol, and the variable names are case sensitive.

The correct method for setting variables in PHP is:

 

$ Var_name   = Value;

PHP beginners often forget the $ symbol before the variable. In this case, the variable will be invalid.

Although variables do not need to be initialized in PHP, this is a good habit. Uninitialized variables have default values of their types-False, Zero, empty string or empty array.

<? PHP

$ VaR   =   ' PHP ' ;
$ VaR   = ' Tutorial Network ' ;
Echo " $ VaR , $ VaR " ; // Output "PHP, tutorial network"

$4 site =   ' Not yet ' ; // Illegal Change name; starting with a number
$ _ 4 site   =   ' Not yet ' ; // Valid variable name; starting with an underscore
$ I site is   =   ' Mansikka ' ; // Valid variable name; Chinese

?>

 

Variable naming rules
    • The variable name must start with a letter or underscore.
    • Variable names can only contain letters, numbers, and underscores.
    • Variable names cannot contain spaces. If the variable name is composed of multiple words, it should be separated by underscores (for example, $ my_string) or begin with an uppercase letter (for example, $ mystring ).

 

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.