PHP operator Classification description and some special operator summaries

Source: Internet
Author: User
Tags arithmetic operators bitwise bitwise operators integer division logical operators php operator
I. Classification of Operators

1, by Operation number classification

1.!true//Unary operators
2. $a + $b//two-dollar operator
3.true? 1:0//ternary operator

2, according to the function classification

(1) Arithmetic operators
1.+ 、-、 x,/,% (take more)

(2) String operators
1.///For example: $a = ' abc '. ' EFG ';

(3) Assignment operator

1.=//Simple Assignment
2.+=,-=, x=,/=,%=,. =//Compound assignment
3.++ ($a + +, + + $a),--($a--、--$a)//increment decrement
4.& ($a = 1; $b = &a)//reference assignment

(4) Comparison operators

1.==, = = = (constant equals),! =,!===, <> (not equal to), <, >, <=, >=

(5) Logical operators
1.//in parentheses with higher precedence than outside parentheses
2.&& (and), | | (OR),! (not), XOR (heterogeneous),

(6) Bitwise operator
1.& (Bitwise AND), | (bitwise OR), ~ (bitwise non), ^ (bitwise XOR), << (left shift), >> (right Shift)

Second, arithmetic operators

% remainder, common usage: 1) integer Division operation 2) control range of values

Example: Judging whether it is a leap year (four years a leap, a century does not leap, 400 years again leap)

% will turn the number of the two sides into integer after the division//% can not be used with decimals or negative if ((($year%4 = = 0) && ($year%100! = 0)) | | $year%400 = 0) echo "Leap year"; Elseecho "common year" ;

Three, assignment operators

First add 10, and then assign to yourself, equivalent to $a = $a +10$a + = ten;  Increment decrement, increment decrement and assign value + + $a//first assignment, then increment decrement $a++//instance $ A = ten, $b = $a + + $c =--$b result: a=11 b=9 c=9

Four, logical operators

XOR: Same as False (two true or two false = False), different for true (one true false = False)
Tips: Note the difference from or two true = True
Logical operator Short Circuit
1, &&//A false, then do not operate, must be false
2, | | One is true, then there is no operation behind it, it must be true.

fopen ("test.php", "R") or Die ("failure");

Tips: For Operators & | No short circuit characteristics

Five, bitwise operators

Bit operation: Convert integer to 32-bit binary, string to Ansca code to handle

VI. Special Operators

Annotation symbols:
Single-line annotations
Multi-line annotations
Use of quotation marks
' Single quotation marks, simple strings, are taken directly by any processing;
"" Double quotes, PHP dynamic processing then output, typically used to process the $ variable.
Boolean variable:
One is true, that is true;
The other is false or false.
Common variables:
string strings (numeric \ Kanji \ etc)
Integer integers (1, 2, 3, 4, 5, 0, 1, 2, and so on)
Double floating point number (decimal point)
Array arrays
Object objects
Available methods are GetType ($mix) and Settype ($mix, $typename);

Common symbol escapes:

\ "Double quotation marks
\ \ Backslash
\ nthe line break
\ r back to the beginning
\ t Horizontal Tabulation
Operation Symbols:
+ addition operations-subtraction operations
* Multiplication Operation/division operation
% take remainder + + 1
--Self minus 1. Connect two strings
Assignment operation:
= Put the value on the right side into the left
+ = Add the right value to the left
-= reduce the value on the right to the left
*= multiply the left value by the right.
/= divide the left value to the right
. = Add the right string to the left
Bit operations:
& Bitwise AND
| Bitwise OR
^ Bitwise XOR (XOR)
<< Move left 1-bit
>> Move right 1-bit
~ Fetch the number of complements
Logical operation:
< less than > greater than
<= less than or equal to >= greater than or equal
! = is not equal to &&
|| Or! Non -
Other operational symbols
$ variable Symbol
& Variable Alias
@ Do not display error message (added before function)
The method or property of the object
= = element value of array
?: Ternary 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.