
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
Number comparisons in PHP 8
When we compare a numeric in PHP 8, it will use number comparison. Else it will convert the number to a string and will use the string comparison.
The string can be categorized in three ways −
A string that contains only numeric. Example − 1234 or 1.24e1.
A leading–numeric string − A leading string starts with a numeric string but it should be followed with non-numeric characters including the white space. Example − 12xyz or “123”
Non-numeric string − The string which cannot be numeric and also a non-leading numeric string.
Example − PHP 7
0=='foo' // PHP 7 will return true.
Example − PHP 8
0 =='foo' // PHP 8 will return false.
Example − PHP 8 program using Saner string to number comparisons.
<?php $x=[ "1" => "first Integer", "0123" =>"The integer index with leading 0", "12str" =>"using leading numeric string", " 1" => "using leading whitespace", "2.2" => "using floating number", ]; print_r($x); ?>
Output
Array ( [1] => first Integer [0123] => The integer index with leading 0 [12str] => using leading numeric string [ 1] => using leading whitespace [2.2] => using floating number )
- Related Articles
- String comparisons in Arduino
- Java Substring Comparisons
- Attributes in PHP 8
- Maximum and minimum of an array using minimum number of comparisons in C
- Named Arguments in PHP 8
- Union Type in PHP 8
- Match Expression in PHP 8
- Nullsafe Operator in PHP 8
- fdiv() function in PHP 8
- File and Directory Comparisons in Python
- Difference between gettype() in PHP and get_debug_type() in PHP 8
- Mixed Pseudo Type in PHP 8
- Constructor Property Promotion in PHP 8
- Middle of three using minimum comparisons in C++
- Role of Post Hoc comparisons in Research Psychology

Advertisements