strnatcmp()函数

WBOY
WBOYOriginal
2016-06-23 13:36:591078browse

strnatcmp()函数是对字符串中的数字按照数字大小比较
$str1="mrsoft1";
$str2="MRSOFT2";
echo strnatcmp($str1,$str2);
预想结果是-1, 结果是1,请问这是什么原因


回复讨论(解决方案)

$str1 = "mrsoft1";$str2 = "MRSOFT2";echo strnatcmp($str1,$str2); //1 因为 m 大于 M$str1 = "mrsoft1";$str2 = "mrsoft2";echo strnatcmp($str1,$str2); //-1 这样才对$str1 = "mrsoft11";$str2 = "mrsoft2";echo strnatcmp($str1,$str2); //1 这才是本意 11 大于 2

之前对函数没有理解到位,以为只比较字符串中的数字大小,忽略了字符的ASCII码值。
谢谢楼上的解答

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn