PHP Learning Notes (ii): Variable details, study notes _php tutorial

Source: Internet
Author: User

PHP Learning Notes (ii): Variable details, study notes


Introduction of PHP Variables

1. Grammar
Copy the 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 a number
2). Cannot use PHP operator (+-x/%&)
3). You can use the PHP keyword
4). Case-sensitive (PHP only variables, constants are case-sensitive)
5). Hump Naming method: AABBCC (first letter lowercase)

3. Variable variable

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

4. Reference Assignment
Copy the Code code as follows:
$a = 1;
$b =& $a; Assigns a value of $ A memory address to $b
$a = 2;
echo $b//Last value equals 1

Second, the variable data type

1. Four kinds of scalar
Copy the Code code as follows:
int (integer), bool (Boolean), float,double (floating-point penalty), String (string)

2, two kinds of compound type
Copy the Code code as follows:
Arrays: Array ()
Objects: Object
For example: $var = new Mysqlli (' localhost ', ' root ', ' 123455 ')

3, two kinds of special types

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

Three, commonly used functions

Copy the Code code as follows:
Isset ()///variable exists and a value of NULL means that it does not exist
Unset ()//release variable
Var_dump ()//Check the type of variable or value
Empty ()//The variable does not exist or returns True when NULL
Settype ($a, int)//Set Variable type
GetType ()//Get variable type

Four, variable declaration method

Copy the Code code as follows:
$int = 10//integer 4-byte, Max 2³²
$float = 3.14e⁴//floating-point equals 3.14x10⁴
$bool = False//true is true
$str = "string"//double quotation mark can parse variable and escape character

You cannot use escape characters, but you can escape the single quotation mark itself for example $str = ' a\ ' a\ '
$str = ' string '

Declaring a string with a delimiter

http://www.bkjia.com/PHPjc/985259.html www.bkjia.com true http://www.bkjia.com/PHPjc/985259.html techarticle PHP Learning Notes (ii): Variable explanation, learning notes in detail one, PHP variable introduction 1, Syntax copy code is as follows://php is a weakly typed language, variable type is determined by the stored value ...

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