function array_searchRecursive( $needle, $haystack, $strict=false, $path=array() )
{
if( !is_array($haystack) ) {
return false;
}
foreach( $haystack as $key => $val ) {
if( is_array($val) && $subPath = array_searchRecursive($needle, $val, $strict, $path) ) {
$path = array_merge($path, array($key), $subPath);
return $path;
} else if( (!$strict && $val == $needle) || ($strict && $val === $needle) ) {
$path[] = $key;
return $path;
}
}
return false;
}
Do any body suggest me the same funcitonality, that can be implemented in javascript.
reference http://www.php.net/manual/en/function.array-search.php#68424
This might give you a start. Not thoroughly tested or highly optimized, and assumes use of jQuery (shouldn’t be a big problem to replace the jQuery utilty functions with other implementations).
http://jsfiddle.net/b8TxJ/2/