PHP study notes (2): Detailed explanation of variables, detailed explanation of study notes_PHP tutorial

WBOY
Release: 2016-07-13 09:56:58
Original
938 people have browsed it

PHP study notes (2): Detailed explanation of variables, detailed explanation of study notes

1. Introduction to PHP variables

1. Grammar
Copy code The code is 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 PHP keyword
4). Case sensitive (php only variables and constants are case sensitive)
5). Camel case nomenclature: aaBbCc (the first letter of the first word is lowercase)

3. Variable variables

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

4. Reference assignment
Copy code The code is as follows:
$a=1;
$b=&$a; //Assign the value of the memory address of $a to $b
$a=2;
echo $b //The last value is equal to 1

2. Variable data type

1. Four kinds of scalars
Copy code The code is as follows:
int (integer), bool (Boolean), float, double (floating point), string (string)

2. Two composite types
Copy code The code is as follows:
Array: array()
Object: object
For example: $var = new mysqlli('localhost','root','123455')

3. Two special types

Copy code The code is as follows:
resource (resource) For example: $var = fopen('test.php','r')
Null (empty type) case-insensitive

3. Common functions

Copy code The code is as follows:
isset() //Whether the variable exists, a value of null means it does not exist
unset() //Release variables
var_dump() //Check the type of variable or value
empty() //Returns true when the variable does not exist or is empty
settype($a,int) //Set variable type
gettype() //Get variable type

4. Variable declaration method

Copy code The code is as follows:
$int = 10 //Integer 4 bytes, maximum value 2³²
$float = 3.14E⁴ //The floating point type is equal to 3.14X10⁴
$bool = false //true is true
$str = "string" //Variables and escape characters can be parsed in double quotes

//You cannot use escape characters, but you can escape the single quote itself. For example, $str = 'a'a''
$str = 'string'

Declare strings using delimiters

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/985259.htmlTechArticlePHP study notes (2): Detailed explanation of variables, detailed explanation of study notes 1. Introduction to PHP variables 1. Syntax copy code code As follows: //PHP is a weakly typed language, and the variable type is determined by the stored value...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template