0
当我使用这个代码就告诉我正确的结果当我在条件中使用true时,strpos函数无法正常工作?
<?php
$string = 'there is some text';
$find = 'some';
function iscontain($string,$find){
$check = strpos($string, $find);
if ($check === false) { return 0; }else{ return 1; }
}
if(iscontain($string,$find)){
echo "true";
}else{
echo "false";
}
//output: true
?>
但是,当我改变假成真,改变返回值一样,如果检查是true,所以返回1,否则为0,从而在逻辑上是正确的,但结果不显示正确
<?php
$string = 'there is some text';
$find = 'some';
function iscontain($string,$find){
$check = strpos($string, $find);
if ($check === true) { return 1; }else{ return 0; }
}
if(iscontain($string,$find)){
echo "true";
}else{
echo "false";
}
//output : false
?>
为什么两个结果都不一样..?谢谢。
请阅读[strpos()']的文档(http://php.net/manual/en/function.strpos.php)。如果找到它,则返回字符串的_position_;如果未找到,则返回“false”。它实际返回“true”时没有状态。 –
[简单的PHP strpos函数不工作,为什么?]可能的重复(https://stackoverflow.com/questions/4858927/simple-php-strpos-function-not-working-why) – mickmackusa