Sep 27, 2008

indexOf in PHP

I found this function very useful in almost every project I do. indexOf() returns element's key in an array.
The parameters for this function are:
- the array to search
- the value to search
Return value is the element key.
function indexof($array,$value) {
foreach($array as $key=>$val)
 if($val == $value) return $key;
}

No comments: