PHP tutorial PHP tutorial Variable definition

Source: Internet
Author: User
Tags alphanumeric characters
Variables in PHP
Variables are used 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, and the variable names are case-sensitive.
The correct way to set variables in PHP is:
$var _name = value; PHP beginners tend to forget the $ symbol in front of the variable. If you do that, the variable will be invalid.
Although it is not necessary to initialize variables in PHP, this is a good habit. An uninitialized variable has a default value of its type-FALSE, 0, an empty string, or an empty array.

Copy the Code code as follows:


$var = ' PHP ';
$Var = ' tutorial net ';
echo "$var, $Var"; Output "PHP, tutorial Net"
$4site = ' not yet '; illegal change of name; start with a number
$_4site = ' not yet '; The name of the legal variable, preceded by an underscore
$i site is = ' Mansikka '; The name of the legal variable; can be in Chinese
?>


Naming rules for variables
The variable name must begin with a letter or underscore "_".
Variable names can contain only alphanumeric characters and underscores.
Variable names cannot contain spaces. If the variable name consists of multiple words, it should be delimited with an underscore (such as $my _string), or start with a capital letter (such as $myString).

The above describes the PHP tutorial PHP tutorial variable definition, including the PHP tutorial content, I hope the PHP tutorial interested in a friend helpful.

  • 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.