note 45701 added to function.array-search
| From: | geoff at hoffmans dot net | Date: | Wed, 15 Sep 2004 15:55:48 +0000 |
| Subject: | note 45701 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-76745@lists.php.net to get a copy of this message | ||
It's not immediately obvious from the docs, so I did my own test to be sure. If you search in a
non-associative array, array_search does indeed return the zero-based numeric index of your search
value. If not found, returns false.
<?php
// test to see if array_search works on non-associative arrays
$array =
array("a","b","c","d","e","g","f");
$pos = array_search("g", $array);
echo $pos; // echoes 5
$pos2 = array_search("N", $array);
if( $pos2 === NULL ) { echo "null" ; }
if( $pos2 === false ) { echo "false" ; } // echoes false
?>
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45701
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45701&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45701&report=yes
Search -- http://master.php.net/manage/user-notes.php