Home >Backend Development >PHP Tutorial >Analysis of usage examples of new operators in PHP7
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:
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<=>'1';
The operation effect diagram is as follows:
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!