I have a multi-dim array to search:
> Array (
>     [91] => Array
>         (
>             [FoSW] => 117
>             [DfLR] => 107
>             [FoA] => 0
>             [SoG] => 116
>             [RST] => 38
>             [SSW] => 0
>             [total] => 458
>         )
> 
>     [92] => Array
>         (
>             [FoSW] => 118
>             [DfLR] => 0
>             [FoA] => 58
>             [SoG] => 0
>             [RST] => 0
>             [SSW] => 40
>             [total] => 463
>         ) //etc....
I am using this function which searches for the value and returns its key. IF the value is not found then it reduces the value by one and searches again.
$search is the md array
$type would be SoG for example (a key in the second level of the md array)
$score would be value 0f 24 for example
NOTE: in the entire array there is no SoG with a value of 24
function find_percentile($search, $type, $score){
    foreach($search as $key=>$val){
        if ($val[$type]== $score){
            return $key;
            $found = true;
        }
        else {
            $found = false;
        }
    }
    if ($found == false){
        $new_score = $score - 1;
        find_percentile($search, $type, $new_score);
    }
}
if I echo $key from the foreach loop it will eventually echo out the recursively found key.
but when i build a separate array with the function or echo the function it does not get the key found by recursion.
$perc_array[$key] = find_percentile($percentiles, $key, $val); 
this will only attach the matched values. Recursively found values will not be in this array.
echo find_percentile($percentiles, $key, $val);
will not echo recursively found values.
 
     
    