note 32683 deleted from function.strpos by didou

From: Date: Sun, 10 Aug 2003 02:59:03 +0000
Subject: note 32683 deleted from function.strpos by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-53784@lists.php.net to get a copy of this message
Note Submitter: mph0879@aol.com ---- 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 :)

« previous php.notes (#53784) next »