note 93852 added to control-structures.if

From: Date: Sat, 03 Oct 2009 11:50:02 +0000
Subject: note 93852 added to control-structures.if
Groups: php.notes 
Request: Send a blank email to php-notes+get-161246@lists.php.net to get a copy of this message
As an added note to the guy below, in such a case, use the !== operator like this. $nkey = array_search($needle, $haystack); if ($nkey !== false) { ... The !== and the === compare the "types". So, with this type of comparision, 0 is not the same as the FALSE returned by the array_search array when it can not find a match. :) Quoted Text: =================================== Be careful with stuff like if ($nkey = array_search($needle, $haystack)) { ... if the returned key is actually the key 0, then the if won't be executed =================================== ---- Server IP: 64.71.164.2 Probable Submitter: 68.97.76.170 ---- Manual Page -- http://www.php.net/manual/en/control-structures.if.php Edit -- https://master.php.net/note/edit/93852 Del: integrated -- https://master.php.net/note/delete/93852/integrated Del: useless -- https://master.php.net/note/delete/93852/useless Del: bad code -- https://master.php.net/note/delete/93852/bad+code Del: spam -- https://master.php.net/note/delete/93852/spam Del: non-english -- https://master.php.net/note/delete/93852/non-english Del: in docs -- https://master.php.net/note/delete/93852/in+docs Del: other reasons-- https://master.php.net/note/delete/93852 Reject -- https://master.php.net/note/reject/93852 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161246) next »