Php array operator (+), string operator (.), logical operator (& amp; AND | ORXOR ). For more information about array operators (+), string operators (.), AND logical operators (AND | ORXOR), see. Php array operator $ a + $ B Union $ a and $ B Union. $ A $ B equals array operators (+), string operators (.), AND logical operators (& AND | OR XOR). For more information, see.
Php array operators
$ A + $ B join $ a and $ B.
$ A = $ B is equal. if $ a and $ B have the same key/value pair, the value is TRUE.
$ A ===$ B. TRUE if $ a and $ B have the same key/value pairs and the order and type are the same.
$! = $ B: TRUE if $ a is not equal to $ B.
$ A <> $ B: TRUE if $ a is not equal to $ B.
$! = $ B incomplete. if $ a is not all equal to $ B, TRUE is returned.
The only array operator in PHP is the + operator. It attaches the array on the right to the array on the left, but duplicate key values are not overwritten.
| The code is as follows: |
|
|
$ A = array ("a" => "apple", "B" => "banana ");
$ B = array ("a" => "pear", "B" => "strawberry", "c" => "cherry ");
$ C = $ a + $ B;
Var_dump ($ c ); |
After the script is executed, the script displays:
| The code is as follows: |
|
|
Array (3 ){
["A"] =>
String (5) "apple"
["B"] =>
String (6) "banana"
["C"] =>
String (6) "cherry"
} |
If the elements in the array have the same key name and value, the comparison is equal.
Example #1 compare arrays
| The code is as follows: |
|
|
$ A = array ("apple", "banana ");
$ B = array (1 => "banana", "0" => "apple ");
Var_dump ($ a = $ B); // bool (true)
Var_dump ($ a ===$ B); // bool (false)
?> |
String operators
There are two string operators. The first is the concatenation operator ("."), which returns the string after the left and right parameters are connected. The second is to connect the value assignment operator (". ="), which attaches the right parameter to the parameter on the left
| The code is as follows: |
|
|
Echo "thr". "ee"; // prints the string "three"
Echo "twe". "lve"; // prints the string "twelve"
Echo 1. 2; // prints the string "12"
Echo 1.2; // prints the number 1.2
Echo 1 + 2; // prints the number 3
?> |
Example
| The code is as follows: |
|
|
$ A = '000000 ';
// This works:
Echo "qwe {$ a} rty"; // qwe12345rty, using braces
Echo "qwe". $ a. "rty"; // qwe12345rty, concatenation used
// Does not work:
Echo 'qwe {$ a} rty'; // qwe {$ a} rty, single quotes are not parsed
Echo "qwe $ arty"; // qwe, because $ a became $ arty, which is undefined
?> |
Logical operators
Example of logical operators in the following table
$ A and $ B And (logical and) TRUE, if both $ a And $ B are TRUE.
$ A or $ B Or (logical or) TRUE, if $ a Or $ B is TRUE.
$ A xor $ B Xor (logical exclusive or) TRUE. if either $ a or $ B is TRUE, but not both.
! $ A Not (logical Not) TRUE, if $ a is Not TRUE.
$ A & $ B And (logical And) TRUE, if both $ a And $ B are TRUE.
$ A | $ B Or (logical Or) TRUE. if $ a Or $ B is set to TRUE.
"And" and "or" have two different operators because they have different operation priorities.
Example
| The code is as follows: |
|
|
($ A = $ _ GET ['var']) | ($ a = 'a default ');
?> |
Example
| The code is as follows: |
|
|
// The following foo () will not be called because they are short-circuited by the operator.
$ A = (false & foo ());
$ B = (true | foo ());
$ C = (false and foo ());
$ D = (true or foo ());
// "|" Has a higher priority than "or"
$ E = false | true; // $ e is assigned (false | true) and returns true.
$ F = false or true; // $ f is assigned to false. [Altair note: "=" has a higher priority than "or"]
Var_dump ($ e, $ f );
// "&" Has a higher priority than "and"
$ G = true & false; // $ g is assigned to (true & false) and the result is false.
$ H = true and false; // $ h is assigned true [Altair note: "=" priority is higher than "and"]
Var_dump ($ g, $ h );
?> |
The output of the preceding routine is similar:
Bool (true)
Bool (false)
Bool (false)
Bool (true)
For more information about operators (+), string operators (.), AND logical operators (AND | or xor), see. Php array operator $ a + $ B Union $ a and $ B Union. $ A = $ B equal...