Home  >  Article  >  Backend Development  >  Analysis of usage examples of new operators in PHP7

Analysis of usage examples of new operators in PHP7

高洛峰
高洛峰Original
2016-12-21 14:52:45912browse

The examples in this article describe the usage of new operators in PHP7. Share it with everyone for your reference, the details are as follows:

NULL merge operator

is actually a transformation of the ternary operator, reducing the amount of code

//原先的做法
//$lig = isset($_GET['lig'])?$_GET['lig']:'bee';
$lig = $_GET['lig']??'bee';
echo $lig;

The operation rendering is as follows:

Analysis of usage examples of new operators in PHP7

Spaceship Operator (combined comparison operator)

Essentially, it is a size comparison operator, but compared to '', the return value is -1 more. It has a similar function to Java's string comparison compareto()

<?php
echo 1<=>1.1;
print (PHP_EOL);//换行符
echo "<br>";
print (1.1<=>1);
echo "<br>";
echo 1<=>&#39;1&#39;;

The operation effect diagram is as follows:

Analysis of usage examples of new operators in PHP7

I hope this article will be helpful to everyone in PHP programming.

For more articles on usage examples of new operators in PHP7, please pay attention to 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