字符串比较说明
当s1
当s1=s2时,返回值= 0
当s1>s2时,返回正数
<span> 1</span> <?<span>php </span><span> 2</span> <span>$str1</span> = 'str100'<span>; </span><span> 3</span> <span>$str2</span> = 'str20'<span>; </span><span> 4</span> <span>echo</span> <span>strcmp</span>(<span>$str1</span>, <span>$str2</span>)."<br>"<span>; </span><span> 5</span> <span>//输出</span><span>-1</span> <span> 6</span> <span>echo</span> <span>strnatcmp</span>(<span>$str1</span>, <span>$str2</span>)."<br>"<span>; </span><span> 7</span> <span>//输出</span><span>1</span> <span> 8</span> <span>echo</span> <span>strncmp</span>(<span>$str1</span>, <span>$str2</span>, 5)."<br>"<span>; </span><span> 9</span> <span>//输出</span><span>-1</span> <span>10</span> <span>11</span> ?>
strcmp(str1, str2)函数按照字符比较两个字符串,即两个字符串自左向右逐个字符比较(按ASCII值大小相比较),直到出现不同的字符或遇'