PHP 8 中的數字比較
當我們在 PHP 8 中比較一個數字時,它將使用數字比較。否則它會將數字轉換為字串並使用字串比較。
字串可以分為三種方式 -
僅包含數字的字串。例如 - 1234 或 1.24e1。
前導數字字串 - 前導字串以數字字串開頭,但應緊跟非數字字元,包括空白。示例 - 12xyz 或“123”
非數字字串 - 既不能是數字也不是前導數字字串的字串。
Example − PHP 7
0=='foo' // PHP 7 will return true.
Example − PHP 8
0 =='foo' // PHP 8 will return false.
示例 - 使用更理智的字串到數字比較的 PHP 8 程式。
<?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); ?>
輸出
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 )
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP