note 80390 added to function.array-search

From: Date: Sun, 13 Jan 2008 21:22:08 +0000
Subject: note 80390 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-135078@lists.php.net to get a copy of this message
If you want my humble opinion, it's really too bad that array_search returns the key at which it has found the needle in haystack. I've just spent an hour figuring out WHY my test with my array would always fail with the first element of the array. I had some code like: if (array_exists($myarray)) {...} It took me a while figuring out why nothing ever happened to the first element that I had defined. Now I get it: the first element I have defined is $myarray[0]! Zero!.. My life would have been easier tonight if the function simply returned TRUE when it does find the needle. It's really too bad... and funny at the same time, so I just thought I'd share. Changing my code to "if (array_exists($myarray) !== FALSE) {...}" should work. I'll just try it now. ---- Server IP: 217.174.196.197 Probable Submitter: 90.55.155.81 ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- https://master.php.net/note/edit/80390 Del: integrated -- https://master.php.net/note/delete/80390/integrated Del: useless -- https://master.php.net/note/delete/80390/useless Del: bad code -- https://master.php.net/note/delete/80390/bad+code Del: spam -- https://master.php.net/note/delete/80390/spam Del: non-english -- https://master.php.net/note/delete/80390/non-english Del: in docs -- https://master.php.net/note/delete/80390/in+docs Del: other reasons-- https://master.php.net/note/delete/80390 Reject -- https://master.php.net/note/reject/80390 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135078) next »