Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. <?php
  2. This <=> operator will offer combined comparison in that it will :
  3.  
  4. Return 0 if values on either side are equal
  5. Return 1 if value on the left is greater
  6. Return -1 if the value on the right is greater
  7. The rules used by the combined comparison operator are same as the currently used comparison operators by PHP viz. <, <=, ==, >= and >. Those who are from Perl or Ruby programming background may already be familiar with this new operator proposed for PHP7.
  8.  
  9. //Comparing Integers
  10.  
  11. echo 1 <=> 1; //ouputs 0
  12. echo 3 <=> 4; //outputs -1
  13. echo 4 <=> 3; //outputs 1
  14.  
  15. //String Comparison
  16.  
  17. echo "x" <=> "x"; // 0
  18. echo "x" <=> "y"; //-1
  19. echo "y" <=> "x"; //1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement