Original PHP Tutorial: Operators
I. arithmetic operators
+-*/% + + --
II. string operators.
III. assignment operators
= + =-= * =/= % =. =
IV. Comparison operators
><>====! = Or <>! =
5. logical operators
& Or and | or! Or not
VI. bitwise operators
& | ^ ~ <>>>>> // Converts all data to binary for calculation.
7. Other operators
? : ''@ =>->::& $
Details
------------------------------------------------------------------------
%
Convert the numbers on both sides into integers before performing operations.
Do not use decimal divisor. do not use a negative number if it cannot be 0.
There are two purposes: Division operation; control range
A. division operation
$ Year = 2010; // calculates whether $ year is a leap year.
If ($ year % 4 = 0 & $ year % 100! = 0) | $ yaer % 400 = 0)
{
Echo & quot; 11111111111111 & quot ";
}
Else
{
Echo & quot; 0000000000000 & quot ";
}
B. Control scope
$ Num = 10900009; // control $ num not greater than 10
Echo $ num % 10;
------------------------------------------------------------------------
Connection operator number
$ Name = "tom ";
$ Age = 27;
$ Height = 1.75;
Echo "My name is: {$ name} my age is: {$ age} my height is: {$ height} meters
";
Echo 'My name is: '. $ name.' My age is: '. $ age.' My height is: '. $ height. 'MI '.'
';
Echo "\ $ age =". $ age;
------------------------------------------------------------------------
& Or and | or! Or not
$ Username = "admin ";
$ Password = "123456 ";
$ Email = "";
If ($ username = "admin" & $ password = "123456 ")
{
Echo "the user name and password are entered correctly
";
}
If ($ username = "" | $ password = "" | $ email = "")
{
Echo "all values cannot be blank
";
}
If (isset ($ email )&&! Empty ($ email) | (isset ($ phone )&&! Empty ($ phone )))
{
Echo "there is a contact method ";
}
------------------------------------------------------------------------
^
Bitwise operators are different or only two data types are true.
------------------------------------------------------------------------
~
Bitwise operators convert 0 and 1 (unary operators)
------------------------------------------------------------------------
</>
The bitwise operator shifts left/right to delete the part that is removed from the left to add 0 to the part that is removed from the left to the right.
The right shift is equivalent to/2, and the left shift is equivalent to * 2.
------------------------------------------------------------------------
>>>
Bitwise operator shifts right unsigned
0 is added for all blank areas
------------------------------------------------------------------------
Special note
Short circuit problem: & and | short circuit may occur // Use & and | during calculation, both sides will calculate this problem.
& When performing an operation, if the previous number is false, whether the subsequent value is true or not, and the entire expression is false, the subsequent operands are not executed.
| During the operation, if the previous number is true, whether or not it is followed by false, and the entire expression is true,
Example:
$ Num = 10;
If ($ num> 5 | $ num ++ <100)
{
}
Echo $ num;
Result: 10
------------------------------------------------------------------------
''
The execution operator uses the content in the back quotes as instructions for execution.
$ Str = 'ipconfig/all ';
Echo'
';echo $str;
echo '
';
------------------------------------------------------------------------
@
Shield warnings and errors
@ GetType ();
Echo "##############
";
------------------------------------------------------------------------
Use () operator priority