gpt4 book ai didi

php - 比较数字字符串

转载 作者:可可西里 更新时间:2023-11-01 13:50:22 25 4
gpt4 key购买 nike

来自问题Type-juggling and (strict) greater/lesser-than comparisons in PHP

我知道 PHP 会尽可能将字符串解释为数字。

"10" < "1a"  => 10 less than 1      expecting  false 
"1a" < "2" => 1 less than 2 expecting true
"10" > "2" => 10 greater than 2 expecting true

但在 "10" < "1a" 的情况下php 返回真。

我不明白这个概念,请帮我澄清一下。

编辑:

但是当我添加 "10" + "1a"它返回 11,这意味着 php 将“10”解释为 10,将“1a”解释为 1。对吗?

最佳答案

A 出现在 9 之后。您可以在这个字符串中看到它,从低到高排序。

0123456789abcdefghijklmnopqrstuvwxyz

所以 10 小于 1a。

关于php - 比较数字字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19724027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com