Q:

Search PHP array for value and get parent key

I'm not sure why but I'm having trouble working out recursion for this issue. Here is a sample data structure:
Array (
    [0] => Array (
        [powers] => Array (
                [0] => Array (
                        [power] => Super Strength
                        [scale] => 8
                    )
                [1] => Array (
                        [power] => Invisibility
                        [scale] => 4
                    )
          )
     )
)

What I need to do, is pass an array to a recursive function, so like this:
get_parent_key($our_array[0]["powers"], "Super Strength");

and have the return value be the parent array index, so in this case, 0. If I were to search for "Invisibility" with this same function, the return value would be 1. 
I'm just brain farting and can't seem to form the correct recursive function. Can anyone help?

A:

You can just use array_search and array_column for this:
$power = 'SuperStrength';
$key = array_search($power, array_column($our_array[0]["powers"], 'power'));
echo "$key\n";
$power = 'Invisibility';
$key = array_search($power, array_column($our_array[0]["powers"], 'power'));
echo "$key\n";

Output:
0
1

Note that array_search returns false (which can be equivalent to 0) if it doesn't find a value, so when checking the result you should use !== false to test for success. For example:
$power = 'Flying';
$key = array_search($power, array_column($our_array[0]["powers"], 'power'));
if ($key !== false) echo "$key\n";
else echo "power $power not found!\n";

Output:
power Flying not found!

Demo on 3v4l.org

