PHP 7 Tutorial
PHP 7 Useful Resources
Selected Reading
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 - Deprecated Features
- PHP 7 - Session Options
- PHP 7 - Integer Division
- PHP 7 - Error Handling
- PHP 7 - use Statement
- PHP 7 - Expectations
- PHP 7 - CSPRNG
- PHP 7 - IntlChar
- PHP 7 - Filtered unserialize()
- PHP 7 - Closure::call()
- PHP 7 - Anonymous Classes
- PHP 7 - Constant Arrays
- PHP 7 - Spaceship Operator
- PHP 7 - Null Coalescing Operator
- PHP 7 - Return Type Declarations
- PHP 7 - Scalar Type Declarations
- PHP 7 - Environment Setup
- PHP 7 - Performance
- PHP 7 - Introduction
- PHP 7 - Home
PHP 7 Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PHP 7 - Spaceship Operator
PHP 7 - Spaceship Operator
In PHP 7, a new feature, spaceship operator has been introduced. It is used to compare two expressions. It returns -1, 0 or 1 when first expression is respectively less than, equal to, or greater than second expression.
Example
<?php //integer comparison print( 1 <=> 1);print("<br/>"); print( 1 <=> 2);print("<br/>"); print( 2 <=> 1);print("<br/>"); print("<br/>"); //float comparison print( 1.5 <=> 1.5);print("<br/>"); print( 1.5 <=> 2.5);print("<br/>"); print( 2.5 <=> 1.5);print("<br/>"); print("<br/>"); //string comparison print( "a" <=> "a");print("<br/>"); print( "a" <=> "b");print("<br/>"); print( "b" <=> "a");print("<br/>"); ?>
It produces the following browser output −
0 -1 1 0 -1 1 0 -1 1Advertisements