php 比较字符串

来源:百度知道 编辑:UC知道 时间:2024/06/17 02:38:03
比较两个身份证号码是否相等(用php)
如果两个身份证中有一个是15位的一个是18位的就替换成18位的
都是15位的就用15位的

<?php
$id1="42022219860323211";
$id2="41045213201201201";
if($id1==$id2){
echo"这两个身份证相同";
}else{
echo"这两个身份证不相同";

}

也可以用 $id1 == $id2 ? '相同' : '不同';

?>
by cubeking &&金先旺

int strcmp ( string str1, string str2 )

Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.

Note that this comparison is case sensitive.

echo $num1 === $num2 ? '相同' : '不同';