I'm reading the programing manual on www.php.net and I ran into something that I don't really understand.
The code is this
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
// We can search for the character, ignoring anything before the offset
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1); // $pos = 7, not 0
?>
What I can't figure out is why do you have to use "===". I'm actually having a hard time understanding why you would have to use "==" if it did work.
Another example is
<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
echo 'You are using Internet Explorer.<br />';
}
?>
Now I understand what its doing here. Basically strpos() is looking inside of "$_SERVER['HTTP_USER_AGENT']" for 'MSIE'.
I understand that part what I don't understand is why the !== FALSE is there. I know that != means Does not Equal, but why the second =?
Can anyone help me out?