Operators in PHP----bit operators, increment-decrement operators, ternary operators, string operators, array operators, type operators, error control operators

Source: Internet
Author: User
Tags bitwise bitwise operators

1, bitwise operators

The bitwise operator is used to set the specified bit of an integer number, and if the operand is a string, the ASCII value of the string is manipulated.

Type of operation Operator Example Results
Bitwise-AND & $a & $b Place $ A and 1 in the $b at 1 and the rest to 0
Bitwise OR | $a | $b Place $ A in 1 or $b to 1 in 1 and 0 for the rest
Bitwise XOR OR ^ $a ^ $b Add $ A to the $b with a different position of 1 and the rest to 0
Bitwise non- ~ ~ $a The position of 1 in the $a is 0, and the position of 0 is 1
Move left << $a << $b When a bit in $ A moves to the left $b times, each move is equal to multiplying by 2
Move right >> $a >> $b When a bit in $ A moves to the right $b times, each move is equivalent to dividing by 2

2. Increment decrement operator

Type of operation Operator Example Results
Pre-increment ++ + + $a $a increment by 1 and return $ A
Post-increment ++ $a + + Return $ A first, then $ A from 1
Before descending -- --$a $a subtract 1, and then return $ A
After descending -- $a-- Return $ A first, then $ A minus 1

3, ternary operator

The ternary operator (?:), also called the trinocular operator, acts like a SELECT statement that selects one of the two other expressions based on the true or false of an expression. Use the following:

Logical expression? Expression 1: Expression 2

Returns expression 1 if the logical expression is true, otherwise returns the expression 2

4. String operators

In PHP, you often see two strings through a small dot "." Connected, the dot is the string operator. With the string operator, you can concatenate any number of strings into a single string.

If there are numeric variables in the operand of the string connector, the PHP engine will convert the its first to a string and then concatenate the strings.

5. Array operators

Type of operation Operator Example Results
Union operations + $a + $b Appends a $ A element to the back of the $b, and the duplicate key value is not overwritten
Equality comparison == $a = = $b Returns True when $ A and $b have the same key value pair, otherwise returns false
Comparison of congruent === $a = = = $b When $ A has the same key-value pair as the $b, and the order and type of the elements are the same, returns true, otherwise false
Unequal comparison ! = or <> $a! = $b When $ A and $b have the same key value pair, return false, otherwise return true
Non-congruent comparison !== $a!== $b When $ A has the same key-value pair as the $b, and the order and type of the elements are the same, returns FALSE, otherwise returns true

6. Type operator

In PHP, the type operator instanceof commonly used to determine whether a variable belongs to an instance of a class. In addition, the type operator can also be used to determine whether a variable is an instance of a subclass that inherits from a parent class, or whether a variable implements an instance of an interface's object.

7. Error control operator

The error control operator uses @ to block the error message that appears before it is placed in an expression that is faulted.

Operator in PHP---bitwise operator, increment decrement operator, ternary operator, string operator, array operator, type operator, error control operator

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.