gpt4 book ai didi

php - PHP 7 中的 <=>( 'Spaceship' 运算符)是什么?

转载 作者:IT老高 更新时间:2023-10-28 11:42:20 25 4
gpt4 key购买 nike

将于今年 11 月发布的 PHP 7 将引入 Spaceship (<=>) 运算符。它是什么以及它是如何工作的?

这个问题已经有an answer在我们关于 PHP 运算符的一般引用问题中。

最佳答案

<=> ("Spaceship") 运算符将提供组合比较:

Return 0 if values on either side are equal
Return 1 if the value on the left is greater
Return -1 if the value on the right is greater

组合比较运算符使用的规则与 PHP viz 当前使用的比较运算符相同。 < , <= , == , >=> .具有 Perl 或 Ruby 编程背景的人可能已经熟悉这个为 PHP7 提出的新运算符。

   //Comparing Integers

echo 1 <=> 1; //output 0
echo 3 <=> 4; //output -1
echo 4 <=> 3; //output 1

//String Comparison

echo "x" <=> "x"; //output 0
echo "x" <=> "y"; //output -1
echo "y" <=> "x"; //output 1

关于php - PHP 7 中的 <=>( 'Spaceship' 运算符)是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30365346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com