note 40889 added to function.array-search

From: Date: Thu, 18 Mar 2004 07:46:03 +0000
Subject: note 40889 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-67001@lists.php.net to get a copy of this message
This is a silly thing, but it can drive you crazy if you do not read the warning above. <?php $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); $key = array_search('blue', $array); // $key = 2; echo $key; if($key==FALSE){ echo "FALSE"; }else{ echo "TRUE"; } ?> It will print FALSE. Use this coding instead: <?php $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); $key = array_search('blue', $array); // $key = 2; //$key = array_search('red', $array); // $key = 1; echo $key; if($key===FALSE){ echo "FALSE"; }else{ echo "TRUE"; } ?> It will return TRUE ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40889 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40889&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40889&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#67001) next »