note 114755 deleted from function.array-search by peehaa
| From: | peehaa@php.net | Date: | Fri, 07 Apr 2017 10:36:15 +0000 |
| Subject: | note 114755 deleted from function.array-search by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-209006@lists.php.net to get a copy of this message | ||
Note Submitter: rAthur
----
If you're not running an older version of PHP (many servers are still on PHP 5.3), you can
replace the function by this :
<?php
function s($needle,$array)
{
foreach($array as $key => $value)
if ($value==$needle)
return $key;
return false;
}
echo s( 'c', array('a', 'b', 'c', 'd') ); //
returns 2
echo s( 'f', array('a', 'b', 'c', 'd') ); //
returns false
?>