note 116421 added to function.array-search
| From: | fatcow at gmail dot com | Date: | Wed, 31 Dec 2014 01:55:49 +0000 |
| Subject: | note 116421 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201284@lists.php.net to get a copy of this message | ||
The array_search method doesn't return true, as one might otherwise expect it to, on the 1st
array node (key: 0).
If you're just trying to detect the existence of a value in an array, then 'in_array'
is the method you'll want to use, not this.
<?php
$array = array(1,2);
// returns false
if (array_search(1,$array))
{
print "checked";
}
// returns true
if (in_array(1,$array))
{
print "checked";
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 2001:4800:7813:516:c4d0:558f:aada:73df
----
Manual Page -- http://php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/116421
Del: integrated -- https://master.php.net/note/delete/116421/integrated
Del: useless -- https://master.php.net/note/delete/116421/useless
Del: bad code -- https://master.php.net/note/delete/116421/bad+code
Del: spam -- https://master.php.net/note/delete/116421/spam
Del: non-english -- https://master.php.net/note/delete/116421/non-english
Del: in docs -- https://master.php.net/note/delete/116421/in+docs
Del: other reasons-- https://master.php.net/note/delete/116421
Reject -- https://master.php.net/note/reject/116421
Search -- https://master.php.net/manage/user-notes.php