有没有更好的方法来检查php中弱变量类型的误报检查(比较两个值)?
0 ==:true,确切为假
4 == 1:true,确切为假
0 ==:true,确切为假
0 == 0:是,确切为假
0 ==:true,确切为假
0 == a:true,确切为假
1 == 01:true,确切为假
==:true,确切为假
3 == 3只狗:是的,确切的错误
100 == 1e2:true,确切为假
100 == 100:true,确切为假
abc == 1:true,确切为假
123 == 123:true,确切为假
123 == +0123:true,确切为假
<?php
function is_equal($value1, $value2, $exact=0) {
$output = "{$value1} == {$value2}: ";
switch($exact) {
case 0:
if ($value1 == $value2) {
$output .= "true, ";
} else {
$output .= "false, ";
} //break;
case 1:
if ($value1 === $value2) {
$output .= "\texact true<br>";
} else {
$output .= "\texact false<br>";
} break;
}
return $output;
} //endof is_equal
echo is_equal(0,false);
echo is_equal(4,true);
echo is_equal(0,null);
echo is_equal(0,"0");
echo is_equal(0,"");
echo is_equal(0,"a");
echo is_equal("1","01");
echo is_equal("",null);
echo is_equal(3,"3 dogs");
echo is_equal(100,"1e2");
echo is_equal(100,100.00);
echo is_equal("abc",true);
echo is_equal(123," 123");
echo is_equal(123,"+0123");
?>
答案 0 :(得分:1)