...or at least some stuff at php.net:
Quote:
chen dot avinadav at vbulletin dot com
13-Apr-2002 05:15
> for those with php <= 4.04, copy this function in the source or
> your code.
While that function is correct, it will always return the first key in the array its value matches needle. (Unlike the original function, which returns the last key.)
The correct function would look more like this:
function array_search($needle, $haystack) {
$match = false;
foreach ($haystack as $key => $value) {
if ($key == $needle) {
$match = $key;
}
}
return $match;
}
|
http://www.php.net/manual/en/function.array-search.php
That's our Chen

Of course I wrote some stuff too:
Quote:
saltymeat at hotmail dot com
24-Jun-2002 03:03
Here's how you can use array_search() to replace all occurances of a value in an array:
function array_replace($a, $tofind, $toreplace)
{
$i = array_search($tofind, $a);
if ($i === false)
{
return $a;
}
else
{
$a[$i] = $toreplace;
return array_replace($a, $tofind, $toreplace);
}
}
Usage:
$a = array(1,2,3);
$a = array_replace($a, 1, 4);
echo $a[0]; // Outputs 4
|
but that's not important compared to Chen