strncmp 函数用于比较两个字符串中指定数量的字符。它会返回一个整数,表示两个字符串的比较结果。
语法:
int strncmp ( string $str1 , string $str2 , int $len )参数说明:
$str1:要比较的第一个字符串$str2:要比较的第二个字符串$len:要比较的字符数返回值:
如果两个字符串在前 len 个字符上相等,则返回 0。如果 str1 小于 str2,则返回一个负数。如果 str1 大于 str2,则返回一个正数。示例:
$str1 = "hello";$str2 = "world";$result = strncmp($str1, $str2, 3);if ($result == 0) { echo "两个字符串的前3个字符相等";} elseif ($result < 0) { echo "str1 小于 str2";} else { echo "str1 大于 str2";} 

