The PHP7 ship is here.

Source: Internet
Author: User



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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.