Operators in PHP

Source: Internet
Author: User
Tags php language

First, Arithmetic Operators

Operator

Name

Describe

Instance

Results

X + y

Add

X and Y's and

2 + 2

4

X-y

Reducing

The difference between x and Y

5-2

3

X * y

By

The product of X and Y

5 * 2

10

X/Y

Except

Quotient of X and Y

15/5

3

X y

Modulo (remainder of division)

The remainder of x divided by Y

5% 2

1

-X

Take counter

X inverse

-2

-2

A. B

collocated

Connect two strings

"Hi". "Ha"

Hiha

Note: The divisor of "/" and "%" cannot be 0, and in the PHP language the operands of both sides are converted to integers before the operation.

Second, Assignment Operators

Operator

Equivalent to

Describe

x = y

x = y

The left operand is set to the value of the right-hand expression

x + = y

x = x + y

Add

X-= y

x = XY

Reducing

X *= y

x = x * y

By

X/= y

× = x/y

Except

X%= y

x = x% y

Modulo (remainder of division)

A. = b

A = A. B

Connect two strings

"= =" with the " === the Difference

==: requires equal values, without requiring the data type to be equal;

=== : Both the required value and the data type must be equal.

Third, increment/decrement operator

operator

name

description

++ x

pre-increment

x plus 1, then return x

x + +

return x, then x plus 1

--x

x minus 1, then returns x

x--

return x, then x minus 1

Four, comparison Operators

Operator

Name

Describe

Instance

x = = y

Equals

Returns True if X equals y

5==8 return False

x = = y

Constant equals

Returns True if X equals Y and they are of the same type

5=== "5" returns false

X! = y

Not equal to

Returns True if X is not equal to Y

5!=8 returns True

X <> y

Not equal to

Returns True if X is not equal to Y

5<>8 returns True

X!== y

Not constant equals

Returns True if X is not equal to Y, or if they are of different types

5!== "5" returns True

X > Y

Greater than

Returns True if X is greater than Y

5>8 return False

X < y

Less than

Returns True if X is less than Y

5<8 returns True

X >= y

Greater than or equal

Returns True if X is greater than or equal to Y

5>=8 return False

X <= y

Less than or equal

Returns True if X is less than or equal to Y

5<=8 returns True

Five, logical Operators

Operator

Name

Describe

Instance

X and Y

And

Returns true if both X and Y are true

X=6
Y=3
(x < ten and y > 1) returns True

X or Y

Or

Returns True if X and Y have at least one true

X=6
Y=3
(x==6 or y==5) returns True

X XOR y

XOR or

Returns True if X and Y have and only one is true

X=6
Y=3
(X==6 xor y==3) returns false

X && y

And

Returns true if both X and Y are true

X=6
Y=3
(x < ten && y > 1) returns True

x | | Y

Or

Returns True if X and Y have at least one true

X=6
Y=3
(x==5 | | y==5) returns false

! X

Non -

Returns True if X is not true

X=6
Y=3
! (x==y) returns True

Six, Array Operators

Operator

Name

Describe

X + y

Collection

Collections of X and Y

x = = y

Equal

Returns True if X and Y have the same key/value pair

x = = y

Identical

Returns True if X and Y have the same key/value pair and have the same type in the same order

X! = y

Not equal

Returns True if X is not equal to Y

X <> y

Not equal

Returns True if X is not equal to Y

X!== y

Bu Heng, etc.

Returns True if X is not equal to Y

Seven, 7. ternary operators:

(EXPRL)? (EXPRL1): (EXPRL2) similar to "If...else", but the ternary operator appears more tidy when the value of Experl is true, the value of EXPRL1 is obtained, and the value of EXPRL2 is taken instead.

Operators in PHP

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.