<?php
$myArr = array();
$myArr['test']['testing'][1] = "dont find me";
$myArr[1][2][3] = "test";
$myArr['one']['two'][1] = "foo";
$myArr['one']['two'][2] = "bar";
function getArrKeys($arr, $value, $existingKeys=NULL){
if(!$existingKeys){
$existingKeys = array();
}
if(is_array($arr)){
$key = array_search($value, $arr);
if($key !== FALSE){
$existingKeys[] = $key;
}else{
foreach($arr AS $k=>$a){
$key = getArrKeys($a, $value, $existingKeys);
if($key){
$existingKeys[] = $k;
$existingKeys = array_merge($existingKeys, $key);
return $existingKeys;
}
}
}
if(count($existingKeys)){
return $existingKeys;
}else{
return FALSE;
}
}else{
return FALSE;
}
}
print '<pre>';
print "Foo
";
print_r(getArrKeys($myArr, "foo"));
print "Bar
";
print_r(getArrKeys($myArr, "bar"));
print "find me
";
print_r(getArrKeys($myArr, "find me"));
print "test
";
print_r(getArrKeys($myArr, "test"));
?>
Results:
Foo
Array
(
[0] => one
[1] => two
[2] => 1
)
Bar
Array
(
[0] => one
[1] => two
[2] => 2
)
find me
test
Array
(
[0] => 1
[1] => 2
[2] => 3
)