PHP operator (Operators)

Source: Internet
Author: User
Tags arithmetic operators php operator
In this section we introduce the PHP operator (Operators).

An operator is something that can produce another value (and thus the entire structure as an expression) by giving one or more of the values (in programming jargon, expressions).

An operator is something so you feed with one or more values (or expressions, in programming jargon) which yields anothe R value (so, the construction itself becomes an expression).

Arithmetic operators (arithmetic Operators)
Operator Description Example Results
+ Add

The

$a + $b

4

Variable $ A and $b and

- Reducing

3-2

$a-$b

1

The difference between the variable $ A and the $b

* By

3*2

$a * $b

6

Product of variable $ A and $b

/ Except

3/2

$a/$b

1.5

The variable $ A divided by the result of $b

Remainder

3/2

$a% $b

1

The variable $ A divided by the remainder of the $b

Assignment operator (Assignment Operators)

The basic assignment operator is =. You might think it's "equal", not really. It actually means assigning the value of the right expression to the left operand.

For example $a = 5, which indicates that the value of 5 is assigned to the variable $a.

In the PHP language, = denotes an assignment, = = equals. = = See the comparison operator below.

Comparison operator (Comparison Operators)
Operator Description Example
== Equals 6==6 returns TRUE
!= Not equal to 7!=8 returns TRUE
< Less than 8<7 return FALSE
> Greater than 8>7 returns TRUE
<= Less than or equal 8<=9 returns TRUE
>= Greater than or equal 8>=9 return FALSE
Logical operators (Logical Operators)
Operator Description Example
&& And and

$a && $b

Returns true if both $a and $b are true

|| OR OR

$a | | $b

True if $a, any one of the $b returns True

! Not non-

! $a

Returns true if the $a is not true

Xor XOR or different

$a XOR $b

If $a, any one of the $b is true, but not both true, returns True

Increment/decrement operator (incrementing/decrementing Operators)
Operator Description Example
++ Increasing

$a + +, return $ A and add a $ A value of 1

+ + $a, $a value plus 1, and then return $ A

-- Decline

$a--, return $ A, and subtract $ A by 1

--$a, the value of $a minus 1, and then return $ A

String operator (Operators)

There are 2 character operators. One is the join operator., which is used to concatenate two strings; one is the join assignment operator. =, which attaches the right argument to the left argument. Examples are as follows:

Operator Example Results
. "Hello". " World " HelloWorld
.=

$a = "Hello";

$a. = "World";

$a. = "World" equals $ A = $a. " World "

The value of the $a is HelloWorld

Combination of assignment operators and arithmetic operators
operator combinations Example Description
+= $a + = 3 $a = $a + 3
-= $a-= 3 $a = $a-3
*= $a *= 3 $a = $a * 3
/= $a/= 3 $a = $a/3
%= $a%= 3 $a = $a% 3
  • 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.