PHP Learning Notes (ii): _php Examples of variable detailed

Source: Internet
Author: User
Tags php operator

Introduction of PHP Variables

1. Grammar

Copy Code code as follows:

PHP is a weakly typed language, and the variable type is determined by the stored value
Strongly typed language: int a = 1
$ Variable name = value

2. Naming rules

1). Cannot start with numbers
2). Cannot use PHP operator (+-x/%&)
3). You can use the PHP keyword
4). Case Sensitive (PHP is only variable, constant case sensitive)
5). Hump nomenclature: AABBCC (first letter lowercase)

3. Variable variable

Variable names can be set dynamically, for example: $ $var

4. Reference Assignment

Copy Code code as follows:

$a = 1;
$b =& $a; Assigns the value of the $a memory address to $b
$a = 2;
echo $b//Last value equals 1

Second, variable data types

1, four kinds of scalar

Copy Code code as follows:

int (integer), bool (Boolean), float,double (floating-point penalty), string (string)

2, two kinds of compound
Copy Code code as follows:

Arrays: Array ()
Objects: Object
For example: $var = new Mysqlli (' localhost ', ' root ', ' 123455 ')

3, two kinds of special types

Copy Code code as follows:

Resource (resources) For example: $var = fopen (' test.php ', ' R ')
Null (NULL type) is case-insensitive

Iii. Common functions

Copy Code code as follows:

Isset ()///variable exists, value NULL indicates no
Unset ()//release variables
Var_dump ()//Check the type of variable or value
Returns True if Empty ()///variable does not exist or is empty
Settype ($a, int)//Set Variable type
GetType ()//Get variable type

Four, variable declaration method

Copy Code code as follows:

$int = 10//int 4 bytes, maximum 2³²
$float = 3.14e⁴//floating-point type equals 3.14x10⁴
$bool = False//true is true
$str = "string"//double quotes to resolve variables and escape characters

You cannot use escape characters, but you can escape the single quotes themselves such as $str = ' a\ ' a\ '
$str = ' string '


declaring strings with delimiters

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.