PHP7 new features add several new operators

(*-*)浩
Release: 2023-02-26 14:30:02
Original
2596 people have browsed it

The two new operators in php7 are <=> 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[&#39;email&#39;] ?? noemail;
Copy after login

can also be written in this form:

$info = $_GET[&#39;email&#39;] ?? $_POST[&#39;email&#39;] ?? ‘noemail&#39;;
Copy after login

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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template