Front-end PHP operators, learn PHP operators
Directory
Arithmetic operator assignment operator comparison operator ternary operator logical operator string operator error control operator increment decrement operator array operator
Defined
the operator is the identification symbol for the operation. PHP operators are generally divided into arithmetic operators, assignment operators, comparison operators, ternary operators, logical operators, string join operators, error control operators , increment decrement operators, and array operators
Arithmetic operators
+(addition) $x$y-(subtraction) $x$y*(multiplication) $x $y/(division) $x$y%(modulo )$x$y
Assignment operators
There are two types of assignment operators for PHP, namely direct assignment "=" and Reference assignment "&"
[1] Direct Assignment
Direct Assignment "=" assigns the value of the right expression to the left operand. It copies the value of the right expression to the left-hand operand. In other words, first apply a piece of memory to the left operand, and then put the copied value in this memory
x =+==*=/=%= y
[2] Reference assignment
Reference assignment & means that both variables point to the same data. It will allow two variables to share a piece of memory, and if the data stored in this memory changes, then the values of the two variables will vary.
PHP $a = "Test content 1"; $b $a ; $c = &$a; $a = "Test content 2"; Echo $b. "
"; // Test content 1 Echo $c. "
"; // Test Content 2?>
Comparison operators
Comparison operators are primarily used for comparison operations
== equals = = congruent ! = Not equal to <> Range !== is not identical ; is greater than < is less than >= is greater than or equal to <= is less than or equal to
php $a = 1 ; $b = "1" ; var_dump ( $a = = $b ); echo "
"; bool (true) var_dump ( $a = = = $b ); echo "
"; bool (false) var_dump ( $a ! = $b ); echo "
"; bool (false) var_dump ( $a <> $b ); echo "
"; bool (false) var_dump ( $a !== $b ); echo "
"; bool (true) var_dump ( $a < $b ); echo "
"; bool (false) ?
Ternary operators
"?:" The ternary operator is a comparison operator, for an expression (EXPR1)? (EXPR2):(EXPR3), if the value of EXPR1 is true, the value of this expression is expr2, otherwise EXPR3
PHP $a =; $b$a >=60? " Pass ":" Failed "; Echo $b; // passing ?>
logical operators
Logical operators are primarily logical operations
and with or or xor && | | or ! Non -
Php$a=TRUE;//a agree $b=TRUE;//B Agree $c=FALSE;//C Objection $d=FALSE;//D against Echo($aand$b);//1 Echo"
"; Echo($aOr$c);//1 Echo"
"; Echo($aXor$cXor$d);//1 Echo"
"; Echo(!$c? "Pass": "does not pass");//through Echo"
"; Echo($a&&$d? "Pass": "does not pass");//does not pass Echo"
"; Echo($b||$c||$d? "Pass": "does not pass");//through?>
String operators
The string join operator is to concatenate two strings
[1] connection operator (.)
PHP $a = ' Hello '; $b $a . ' world! ' ; // Hello world! Echo $b ;? >
[2] Connection assignment operator (. =)
PHP $x = ' Hello '; $x . = ' world! ' ; // Hello world! Echo $x ;? >
Error control operator
PHP provides an error control operator @, for some expressions that may have errors in the run, and you do not want to display an error message when the fault occurs, put @ before a PHP expression. If the Track_error attribute is activated, any error information generated by the expression is stored in the variable $php_errormsg, which will be overwritten every time an error occurs.
[note] The error control prefix @ does not mask parsing error information, it cannot be placed before the definition of a function or class, nor can it be used for conditional structures such as if and foreach
PHP$a = 1; Echo $a; // 1 $b ; Echo $b; // No error ?>
Increment/decrement operator
+ +$x before increment $x+ + increment - - decrement before $x $x-- decrement after
PHP$x=10echo + +$x// output$y=10Echo $y// output:$z=5; Echo --$z// output 4$i=5; Echo $i // Output 5?>
Array operators
Used to compare arrays
+ union = = equal = = = Congruent ! = unequal <> unequal!== Not congruent
Php$x=Array("A" and "Red", "b" = "green")); $y=Array("c" = "Blue", "d" = "Yellow"); $z=$x+$y; Var_dump($z);//Array (4) {["a"]=> string (3) "Red" ["B"]=> string (5) "Green" ["C"]=> string (4) "Blue" ["D"]=> string (6) "Y Ellow "}Echo"
";Var_dump($x==$y);//bool (FALSE)Echo"
";Var_dump($x===$y);//bool (FALSE)Echo"
";Var_dump($x!=$y);//bool (TRUE)Echo"
";Var_dump($x<>$y);//bool (TRUE)Echo"
";Var_dump($x!==$y);//bool (TRUE)?>
http://www.bkjia.com/PHPjc/1087142.html www.bkjia.com true http://www.bkjia.com/PHPjc/1087142.html techarticle frontend php operator, learn PHP operator directory arithmetic operator assignment operator comparison operator ternary operator logical operator string operator error control operator increment recursion ...