1. In PHP 0 and FALSE are same when you will use == operator but not same when you will use === operator.=== operator checks the type and value so use === operator to check whether a function returns FALSE or not specially in case of those built in function those return FALSE in case of not finding desired result (e.g : stripos).
stripos returns FALSE if it can not find the desired needle in the haystack. so consider the following example.
//////////////////////////////
$haystack = "Basics of PHP";
$needle ="Basics";
if(stripos($haystack,$needle)==false)
echo "Match found";
///////////////////////////
This will output "Match found";
But the output should have been given if the the needle was not in the haystack. But since the needle (in this case "Basics") was in the 0 position of the haystack the stripos is returning 0. and we are using == operator . that means here false and 0 becomes same.
But if the code was like this
//////////////////////////////
$haystack = "Basics of PHP";
$needle ="Basics";
if(stripos($haystack,$needle)===false)
echo "Match found";
///////////////////////////
This will not output anything.
Great discussion and start.We need more this type of post.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteNice, Please continue it sequentially, what will be more helpful specially for the beginners.
ReplyDelete