Home  >  Article  >  Backend Development  >  PHP7 new features add several new operators

PHP7 new features add several new operators

(*-*)浩
(*-*)浩Original
2019-10-14 10:24:312545browse

The two new operators in php7 are 96b4fef55684b9312718d5de63fb7121 and ??.

PHP7 new features add several new operators

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 96b4fef55684b9312718d5de63fb7121 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn