Variables and operators for PHP

Source: Internet
Author: User
This article introduces the contents of the PHP variables and operators, has a certain reference value, now share to everyone, the need for friends can refer to Variable variable
is to precede the variable name with $, the value of the variable as the name of the variable
Reference variable
It's the equivalent of giving a variable a different name.
& For Access symbols
Attention
1. Only variables can be referenced
2, the reference variable after one changes the other also changed
3, the reference value unset off a variable when only the reference relationship is lifted. If the unset variable is referenced by another variable, the unset-off variable does not release memory, but destroys the name of the variable.
Constant
A constant is an identifier for a single value that cannot be modified and destroyed after completion of the definition.
Role
Cannot be changed with the program, so the relative variables are more secure
Statement
Define (' Constant name ', ' constant value ')
Attention
Do not precede the constant name with $
The name of the constant is case-sensitive, and we declare that the variable is generally capitalized
A constant does not exist, it is treated as a string, but it is more efficient
Constants cannot be released, if unset will give an error
The value of a constant cannot be a resource
System constants
Php_version Version of PHP program
Magic Constants
Will change as the unknown changes in the code.
__line__ Current line number
__file__ the full path of the current script
__dir__ the absolute path of the directory where the current script resides
Use defined (' Constant name ') to determine whether a constant exists
Operator
Operational element Partitioning
Unary operations
Binary operations
Ternary operations
Division of functions
If there are strings in the operand you need to first convert the string to an integer or a floating-point number
1. Arithmetic operators
+ - * /
% take-up (modulo)
1, the positive or negative of the mold depends entirely on the first number
2, if the first number is less than the second number of the result of the first number of modulo
+ + self-adding and--self-reduction
Note: + + (-) can be placed in front of the operand and can be placed after the operand, but the meaning is different
Put in the back of the operand, and then add/subtract before
Put in front of the operand, add/subtract after
Note: Boolean types do not participate in self-add/subtract
2. Assignment operators
Assign the value to the right of the equal sign to the variable
+=
$a +=1 equivalent to $a = $a +1
-=
$a-=1 equivalent to $a = $a-1
*=
$a-=1 equivalent to $a = $a *
/=
$a-=1 equivalent to $a = $a/1
%=
$a-=1 equivalent to $a = $a%1
.=
$a. = ' A ' is equivalent to $a = $a. ' A '
3. Comparison operators
The result value of the comparison operator is a Boolean type
> Greater than sign
< less sign
>= greater than or equal to
<= less than or equal to
= = equals number
Note: one = assignment, two = = equals three = = = = All equals (both values and types need to be the same)
PHP is a weakly typed language that lets you compare different types of values. (The two different types will be converted to the same type before the comparison process)
! = does not equal
!== Not all equal to
A spaceship peculiar to the PHP7
$a <=> $b
A result of 0 means $ A equals $b
A result of 1 means $ A greater than $b
The result is-1 = $ A less than $b
Small tools
Isset ()
Returns TRUE if the variable exists and the value exists and is not NULL. otherwise returns false
Empty ()
To see if a variable is empty
Case where the variable is empty
0
“ ”
"0"
Null
False
Array () empty arrays
Variable variable
is to precede the variable name with $, the value of the variable as the name of the variable
Reference variable
It's the equivalent of giving a variable a different name.
& For Access symbols
Attention
1. Only variables can be referenced
2, the reference variable after one changes the other also changed
3, the reference value unset off a variable when only the reference relationship is lifted. If the unset variable is referenced by another variable, the unset-off variable does not release memory, but destroys the name of the variable.
Constant
A constant is an identifier for a single value that cannot be modified and destroyed after completion of the definition.
Role
Cannot be changed with the program, so the relative variables are more secure
Statement
Define (' Constant name ', ' constant value ')
Attention
Do not precede the constant name with $
The name of the constant is case-sensitive, and we declare that the variable is generally capitalized
A constant does not exist, it is treated as a string, but it is more efficient
Constants cannot be released, if unset will give an error
The value of a constant cannot be a resource
System constants
Php_version Version of PHP program
Magic Constants
Will change as the unknown changes in the code.
__line__ Current line number
__file__ the full path of the current script
__dir__ the absolute path of the directory where the current script resides
Use defined (' Constant name ') to determine whether a constant exists
Operator
Operational element Partitioning
Unary operations
Binary operations
Ternary operations
Division of functions
If there are strings in the operand you need to first convert the string to an integer or a floating-point number
1. Arithmetic operators
+ - * /
% take-up (modulo)
1, the positive or negative of the mold depends entirely on the first number
2, if the first number is less than the second number of the result of the first number of modulo
+ + self-adding and--self-reduction
Note: + + (-) can be placed in front of the operand and can be placed after the operand, but the meaning is different
Put in the back of the operand, and then add/subtract before
Put in front of the operand, add/subtract after
Note: Boolean types do not participate in self-add/subtract
2. Assignment operators
Assign the value to the right of the equal sign to the variable
+=
$a +=1 equivalent to $a = $a +1
-=
$a-=1 equivalent to $a = $a-1
*=
$a-=1 equivalent to $a = $a *
/=
$a-=1 equivalent to $a = $a/1
%=
$a-=1 equivalent to $a = $a%1
.=
$a. = ' A ' is equivalent to $a = $a. ' A '
3. Comparison operators
The result value of the comparison operator is a Boolean type
> Greater than sign
< less sign
>= greater than or equal to
<= less than or equal to
= = equals number
Note: one = assignment, two = = equals three = = = = All equals (both values and types need to be the same)
PHP is a weakly typed language that lets you compare different types of values. (The two different types will be converted to the same type before the comparison process)
! = does not equal
!== Not all equal to
A spaceship peculiar to the PHP7
$a <=> $b
A result of 0 means $ A equals $b
A result of 1 means $ A greater than $b
The result is-1 = $ A less than $b
Small tools
Isset ()
Returns TRUE if the variable exists and the value exists and is not NULL. otherwise returns false
Empty ()
To see if a variable is empty
Case where the variable is empty
0
“ ”
"0"
Null
False
Array () empty arrays

Related recommendations:

Learn about the variable range of PHP

PHP's operator and process analysis

Operators for PHP 8:php

Related Article

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.