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

Analysis of usage examples of new operators in PHP7

高洛峰
Release: 2023-03-03 20:12:01
Original
966 people have browsed it

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

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

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!


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