A detailed description of the expressions and operators in PHP

Source: Internet
Author: User
Tags integer division
PHP Operators and expressions

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 an integer and divide the
% cannot use decimal or negative numbers on both sides
if (($year%4 = = 0) && ($year%100! = 0)) | | $year%400 = = 0)
echo "Leap year";
Else
echo "Common year";

Three, assignment operators

Add 10 first and then assign to yourself, equivalent to $a = $a +10
$a + = 10;

Increment decrement, increment decrement first, and then assign value
+ + $a

Assign value first, then increment decrement
$a + +
Instance
$a = 10;
$b = $a + +
$c =--$b
Results: 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

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.