I. arithmetic operators
- + (Plus) $ a + $ B
- -(Minus) $ a-$ B
- * (Multiplication) $ a * $ B
- /(Except) $ a/$ B
- % (Remainder) $ a % $ B
II. string operators
- . (Point) (the only string operator in php)
III. assignment operators 1. simple value assignment operator
- = (Equal to no)
2. Compound assignment operator
- + = $ A + = $ B is equivalent to $ a = $ a + $ B
- -= $ A-= $ B is equivalent to $ a = $ a-$ B
- * = $ A * = $ B is equivalent to $ a = $ a * $ B
- /+ $ A/= $ B is equivalent to $ a = $ a/$ B
- % = $ A % = $ B is equivalent to $ a = $ a % $ B
- . = $ A. = $ B is equivalent to $ a = $ a. $ B
3. Pre-increment and decrement operations and post-increment and decrement operations
- The value of $ a ++ $ a is not changed, but the value of the entire expression is changed to $ a + 1.
- ++ $ A's value has changed. $ a is first $ a = $ a + 1, and then $ a + 1 is returned.
- $ A -- $ a's own value has not changed, but the value of the entire expression will become $ a-1
- -- $ A's value has changed. $ a is first $ a = $ a-1, and then $ a + 1 is returned.
4. Reference operators
- &
Reference operator & can be used in correlated values. Generally, when the value of a variable is assigned to another variable, a copy of the variable is generated first, and then stored elsewhere in the memory. For example:
- $ A = 5;
- $ B = $;
In the above example, the first line of code is to assign a value to $ a, and the second line of code is to generate a copy of $ a, and then save it in $ B. If you change the value of $ a subsequently, the value of $ B will not change. Let's look at the example below:
- $ A = 5;
- $ B = & $;
- $ A = 7; // $ a and $ B are now both 7
Note: The reference is not an independent second pointer, but uses the pointer of the original variable, that is, both $ a and $ B point to the same address of the memory. In the above example, the second row is $ a referenced by $ B. When the value of $ a in the third row changes, the $ B that has referenced it also changes. We can reset to break this reference Association:
- Unsert ($ );
Note: This reset only resets $ a and does not change the value of $ B (7). unsert ($ a) only destroys the association between $ a and 7 stored in the memory. Unsert ($ a) can be interpreted as deregistering $. IV. Comparison operators The comparison operator returns a logical boolean value: true or false.
- = (Equal)
- ===( Constant equals)
- ! = (Not equal)
- ! = (Not constant)
- <> (Not equal)
- <(Less)
- > (Greater)
- <== (Less than or equal)
- >== (Greater than or equal)
5. logical operators
- ! (Not)
- & (And)
- | (Or)
- And (and)
- Or (or)
- Xor (exclusive or) $ a xor $ B returns true if $ a or $ B is true. If both $ a and $ B are true or both false, false is returned.
Note: and or are lower than & |. VI. bitwise operators Bitwise operators can treat an integer variable as the Bit (Bit, Bit) of some columns. Bit operators are not frequently used.
- & (Bitwise AND) $ a & $ B perform the "and" operation on each digit of $ a and $ B.
- | (By bit or) $ a | $ B performs the "or" operation on each digit of $ a and $ B.
- ~ (Not by bit )~ $ A: the result of a "non" operation on each digit of $.
- ^ (Bitwise OR) $ a ^ $ B returns the result of the "xor" operation for each digit of $ a and $ B
- <(Left shift) $ a <$ B shifts $ a left to $ B
- >>( Right shift) $ a >>$ B shifts $ a to the right of $ B
7. Other operators
- , (Comma) is used to separate function parameters or other list items. this operator is often used with (not independent.
- New (initialization class instance)
- -> (Member of the category class)
1. ternary operators? :
- Condition? Value if true: value if false
The ternary operator can be seen as a shorthand for the if else conditional statement. 2. error suppression operators
- @ (At symbol)
Error suppression operator @ can be used before any expression, that is, before any expression with a value or a value that can be calculated, for example:
- $ A = @ (57/0 );
If the error suppression operator @ is not used in the above example, the code in this row will throw a warning except 0. if @ is used, the warning will be blocked, that is, it will not be thrown. If we use this method to suppress some warnings and encounter one warning, we need to write a statement to handle errors in advance. If the track_errors feature in php. ini is enabled, the error message is saved in the global variable $ php_errormsg. 3. execution operators
- ''(A pair of reverse single quotes) is actually a pair of operators, which is a pair of reverse single quotes.
Php will try to run the command between single quotes in reverse direction as a server command. The expression value is the execution result of the command. For example, in a unix system, you can use:
- $ Out = 'ls-LA ';
- Echo'
' . $out . ' ';
On windows Server, you can use:
- $ Out = 'dir c :';
- Echo'
' . $out . ' ';
In both cases, a directory list is obtained and saved in $ out. then, the list is displayed in the browser or processed in other ways. 4. array operators Note: In the following syntax description, $ a and $ B are not common scalar values, but arrays.
- + (Union) $ a + $ B returns an array containing all elements in $ a and $ B.
- = (Equivalent) $ ==$ B returns true if $ a and $ B have the same key-value pair.
- ===( Constant) $ a ===$ B if $ a and $ B have the same key-value pairs and the same order, true is returned.
- ! = (Non-equivalent) $! = $ B if $ a and $ B are not equivalent, true is returned.
- <> (Non-equivalent) $ a <> $ B returns true if $ a and $ B are not equivalent.
- ! ==( Non-constant) $! = $ B if $ a and $ B are not constant, true is returned.
5. type operators Instanceof (a unique type operator), which is used in object-oriented programming. The instanceof operator allows you to check whether an object is an instance of a specific class. For example:
- Class sampleClass ();
- $ MyObject = new sampleClass ();
- If ($ myObject instanceof sampleClass ){
- Echo 'myobject is an instance of sampleclass ';
- }
- ?>
|