您的位置:首页 > 编程语言 > PHP开发

php中常用的字符串比较函数strcmp()实例解释

2017-10-08 16:51 821 查看
int strcmp ( string $str1 , string $str2 )以二进制方式进行比较
以该函数比较时区分大小写
返回值,如果str1小于str2返回<0,如果str1大于str2返回>0如果两者相等返回0。
<?php
$str1 = "hello world";	//$str1与$str3的值相等
$str2 = "HELLO WORLD";
$str3 = "hello world";	//$str1与$str3的值相等

echo strcmp($str1,$str2);	//输出1
echo strcmp($str2,$str1);	//输出-1
echo strcmp($str1,$str3);	//输出0
?>
还有个函数strcasecmp(),用法与strcmp()类似,只是不区分大小写而已,这里不再啰嗦了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php 字符串 strcmp