note 32683 added to function.strpos
| From: | mph0879 at aol dot com | Date: | Wed, 04 Jun 2003 12:24:07 +0000 |
| Subject: | note 32683 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-49710@lists.php.net to get a copy of this message | ||
Just a quick note... maybe this has already been covered, but this pertains to using the ===
operator. I have a script that takes an enum or set , puts the individual options into a
multiple-selection box, and automatically sets each option to "selected" if it's
stored in the DB. However, I was running into a problem... the first enum or set item would never
pass the test... The orginal code read as follows:
// $pertainsTo is a "set" type with a list of operating systems
// $elem is the individual element found in the set
if strpos ($pertainsTo, $elem) { echo "selected "; }
I used the === trick (for comparing a varibale to 0), but that only selected the first one.
Finally, this worked:
$pos=strpos($pertainsTo, $elem);
if ( $pos === 0 || $pos ) { echo "selected "; }
If you already know this sorry, if not, glad I could help :)
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32683
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32683&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32683&report=yes