The two new operators in php7 are <=> and ??.
In PHP7, a new feature was introduced, the null coalescing operator (??). Since there are a lot of situations where ternary expressions and isset() are used simultaneously in PHP7 projects, the new null merge operator can be used to replace the ternary operation and isset() function. If the variable exists and If not null, the null coalescing operator returns its first operand; otherwise it returns its second operand. (Recommended learning: PHP video tutorial)
How to write the PHP7 version:
$info = $_GET['email'] ?? noemail;
can also be written in this form:
$info = $_GET['email'] ?? $_POST['email'] ?? ‘noemail';
The spaceship operator is also called the combined comparison operator or the combined comparison operator. It uses the symbol <=> to represent . This operator can be used to implement the comparison of two variables. Comparison (not limited to numeric type data).
The spaceship operator is a new feature introduced in PHP7. In PHP7, it is used to compare two expressions: when the first expression is less than, equal to, or greater than the second expression respectively formula, the value it returns is: -1, 0, or 1.
PHP7 The expression of the spaceship operator is:
$z = $x <=> $y;
The meaning expressed by the above code is as follows:
If $x > $y, then the value of $z is 1;
If $x == $y, then the value of $z is 0;
If $x < $y , then the value of $z is -1;
The above is the detailed content of PHP7 new features add several new operators. For more information, please follow other related articles on the PHP Chinese website!