Home > Backend Development > PHP Tutorial > strnatcmp()函数

strnatcmp()函数

WBOY
Release: 2016-06-23 13:36:59
Original
1059 people have browsed it

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
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template