Heck, even I got it wrong ;)  True check below should always fail...

Jason Barnett wrote:


Because === and !== check the type as well. Of you set $string = 'blah' you'll still get the same result.

If you were using != and == both would print.

strpos() returns an int, so comparing it to false with === is always
false. The same would be true for true.



That's half right. strpos actually *can* return false as opposed to 0, so checking doing the === check might be necessary for your application.


<?php

$string = 'blah';
if (strpos($string, 'not in the original $string') === false){
  echo 'False check succeeded - not in $string.';
}

if (strpos($string, $string) === true) {
  echo 'True check succeeded - in string';
} else {
  echo 'True check failed - because strpos was at offset 0.';
}

?>

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to