Re: strpos mystery
| From: | Justin Patrin | Date: | Thu, 29 Jul 2004 01:01:19 +0000 |
| Subject: | Re: strpos mystery | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-192139@lists.php.net to get a copy of this message | ||
On Wed, 28 Jul 2004 17:50:01 -0700, Jon Drukman <jsd@cluttered.com> wrote:
> with this code fragment:
>
> <?
>
> $string='/mobile/phone.html';
> if (strpos($string,'/mobile/')!==false) { print "one: yes\n"; }
> if (strpos($string,'/mobile/')===true) { print "two: yes\n"; }
>
> ?>
>
> only the first if statement prints anything. why is !== false not the
> same as === true ?
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.
>
> -jsd-
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> !DSPAM:410846c1241919501214933!
>
>
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--