The combined comparison operator () is a very useful operator. This article will show you how to use the combined comparison operator (). I hope it will be useful to you. help.
Combined comparison operator ()
## operation operator is a three-way comparison operator that performs greater than, less than, and equality comparisons between two operands. [Video tutorial recommendation:PHP tutorial]
Example:1 2 3 |
|
Explanation: <=>The operator behaves like strcmp( ) or version_compare(); it can be used with integers, floats, strings, arrays, objects, etc.
<=> The combined comparison provided by the operator:
● If the values on both sides are equal, 0 is returned ● If the left If the value on the right side is greater, return 1 ● If the value on the right side is greater, return -1Code example
Let’s use code examples to see how the <=> operator performs combined comparisons.Example 1: Integer comparison
1 2 3 4 5 6 7 8 |
|
) in PHP7? (code example)" >) in PHP7? (code example)" alt="How to use the combined comparison operator (<=>) in PHP7? (code example)"/>
Example 2: Floating point number Comparison
1 2 3 4 5 6 7 8 9 |
|
) in PHP7? (code example)" >) in PHP7? (code example)" alt="How to use the combined comparison operator (<=>) in PHP7? (code example)"/>
Example 3: String comparison
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Example 4: Array comparison
1 2 3 4 5 6 7 8 9 10 11 |
|
The above is the detailed content of How to use the combined comparison operator (<=>) in PHP7? (code example). For more information, please follow other related articles on the PHP Chinese website!