Array operator (+), string operator (.), logical operator (&& and | | OR XOR) have a friend to refer to.
PHP Array Operators
$a + $b Union of Joint $a and $b.
$a = = $b equal if the $a and $b have the same key/value pairs true.
$a = = = $b congruent if $a and $b have the same key/value pairs and the order and type are the same, TRUE.
$a! = $b is TRUE if the $a does not equal $b.
$a <> $b If the $a is not equal to $b true.
$a!== $b Not equal to TRUE if the $a is not all equals $b.
The only one array operator in PHP is the + operator. It appends the right array to the left array, but the duplicate key values are not overwritten.
The code is as follows |
Copy Code |
$a = Array ("A" = "Apple", "b" = "banana"); $b = Array ("A" = "pear", "b" = "Strawberry", "c" = "cherry"); $c = $a + $b; Var_dump ($c); |
Once executed, this script will display:
The code is as follows |
Copy Code |
Array (3) { ["A"]=> String (5) "Apple" ["B"]=> String (6) "Banana" ["C"]=> String (6) "Cherry" } |
The cells in the array are compared when they have the same key name and value.
Example #1 Compare arrays
The code is as follows |
Copy Code |
$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 one is the join operator (".") ), which returns the string after its left and right arguments are concatenated. The second is the Join assignment operator (". ="), which attaches the right argument to the left argument
The code is as follows |
Copy Code |
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 ?> |
Cases
The code is as follows |
Copy Code |
$a = ' 12345 '; 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 is not parsed echo "Qwe$arty"; Qwe, because $a became $arty, which is undefined ?> |
logical operators
The following table provides examples of logical operators
$a and $b and (logical AND) true if both $a and $b are true.
$a or $b or (logical OR) true if either $a or $b is true.
$a XOR $b xor (Logical XOR) True if $a or $b any one is true, but not both.
! $a not (logical not) True if $a is not true.
$a && $b and (logical AND) true if $a and $b are true.
$a | | $b or (logical OR) true if either $a or $b is true.
There are two different form operators for "and" and "or" because their operations have different precedence.
Cases
The code is as follows |
Copy Code |
($a = $_get[' var ') | | ($a = ' a default '); ?> |
Cases
The code is as follows |
Copy Code |
The following foo () is not called because they are "shorted" 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 a value of (false | | true), and the result is true $f = False or true; $f is assigned false [Altair NOTE: ' = ' has a higher precedence than ' or '] Var_dump ($e, $f); "&&" has a higher priority than "and" $g = True && false; $g is assigned (true && false) and the result is false $h = True and false; $h is assigned true [Altair Note: ' = ' has a higher precedence than ' and '] Var_dump ($g, $h); ?> |
The output of the above routines is similar to the following:
BOOL (TRUE)
BOOL (FALSE)
BOOL (FALSE)
BOOL (TRUE)
http://www.bkjia.com/PHPjc/628946.html www.bkjia.com true http://www.bkjia.com/PHPjc/628946.html techarticle array operator (+), string operator (.), logical operator (and | | OR XOR) have a friend to refer to. The PHP array operator $a + $b union $a and $b. $a = = $b equal ...