Find values in multidimensional arrays
<p>I've a multidimensional array:</p>

<pre><code>array (
    array (
        "username"        =&gt; "foo",
        "favoriteGame"    =&gt; "Mario"
    )
    array (
        "username"        =&gt; "bar",
        "favoriteGame"    =&gt; "Mario"
    )
    array (
        "username"        =&gt; "xyz",
        "favoriteGame"    =&gt; "Zelda"
    )
)
</code></pre>

<p>How could I get the usernames of the persons that like to play for example Mario the easiest way possible?</p>

<p><strong>EDIT:</strong>
My fault: forget to explicitly mention that the "favoriteGame" value is dynamic and I cannot know which it is in advance.</p>

<p><strong>My Solution:</strong></p>

<pre><code>foreach($users as $key =&gt; $value)
{
    if(!isset($$value['favoriteGame']))
    {
        $$value['favoriteGame'] = array();
    }
    array_push($$value['favoriteGame'], $value['username']);
}
</code></pre>

<p>Iterate over each sub-array and find its favoriteGame value.
If there is not already an array $favoriteGame create it.
Push the username-value of the actual sub-array to the $favoriteGame array.</p>

<p>Thanks for your replies, I just couldn't phrase this question properly.</p>
