
$target="abcde";
$word="abnc";
if(strpos($target,$word) !==false){
echo "contains";
print_r(strpos($target,$word));
}else{
echo "nothing";
print_r(strpos($target,$word));
}
これ当たり前に、nothing つまり含まれないという結果になります。
print_rの方は、0になります。当たり前です。
比較にfalseをstrposの説明どおりに使っているからです。
しかし、ここをnullにすると
$target="abcde";
$word="abnc";
if(strpos($target,$word) !==null){
echo "contains";
print_r(strpos($target,$word));
}else{
echo "nothing";
print_r(strpos($target,$word));
}
containsつまり、含むが返ってきてしまうのです。
nullとか、もしくかして0でもいいのかなどと考えてしまうと
まったく正しく機能しなくなります。
WEBプログム、WEBデザインなどの制作については、以下を御覧ください。
WEBプログム、WEBデザインなどの制作ハイフンが違う »