The eye? The ship here is not a real spaceship, it is a spaceship symbol (<=>).
In PHP7, a new function, the spaceship operator has been introduced. It is used to compare two expressions. When the first expression is less than the second expression, equal to or greater than it returns -1,0 or 1.
<?php//integer comparison print (1 <=> 1);p rint ("<br/>"); Print (1 <=> 2);p rint ("<br/>"); Print (2 <=> 1);p rint ("<br/>"); Print ("<br/>"); Floating point comparison print (1.5 <=> 1.5);p rint ("<br/>"); Print (1.5 <=> 2.5);p rint ("<br/>"); Print (2.5 <=> 1.5);p rint ("<br/>"); Print ("<br/>"); string comparison print ("A" <=> "a");p rint ("<br/>"); Print ("A" <=> "B");p rint ("<br/>"); Print ("B" <=> "a");p rint ("<br/>"); >
In the previous blog post the pit of the PHP floating point comparison was submitted, and finally the BCCMP () function was used to cast the string to resolve.
>> details see: PHP7 mining Pit: Floating-point data comparison
So today, with the new feature of PHP7, you can jump out of a hole perfectly.
$a = 42735.04; $b = 17806.2; $c = $a/36; $c = Round ($c, 2); $d = $c * 15;echo ' $b value is: '. $b. "\ n"; Echo ' $d value is: '. $d. "\ n"; echo "<br/>"; if ((Round ($b, 2) <=> round ($d, 2) = = = 0) {echo "ok\n";} else {echo "sorry\n";}
<=> take off.
This article is from the "My PHP path" blog, so be sure to keep this source http://phpme.blog.51cto.com/663593/1956225
The PHP7 ship is here.