php array_search find index value
<p>I have 2 arrays <code>$userArray</code> and <code>$differentArray</code>.  <br/><br/>
<strong>question:</strong> I am trying to find the index value from <code>$userArray</code> where <code>$userId</code> matches from <code>$differentArray</code> so that i can pull the first/last names<br/></p>

<p><code>print_r</code> of $userArray outputs this:<br/></p>

<pre><code>    Array
    (
        [0] =&gt; Array
            (
                [userId] =&gt; ID Object
                    (
                        [_unknown:protected] =&gt; 
                        [id_:protected] =&gt; 8k6Y4FTrnxKY45XrVkXvVJhL
                    )
                [firstName] =&gt; Joe
                [lastName] =&gt; Smith
            )

        [2] =&gt; Array
            (
                [userId] =&gt; ID Object
                    (
                        [_unknown:protected] =&gt; 
                        [id_:protected] =&gt; pCvR9qvIgGv8WyejcKmRtGD8
                    )
                [firstName] =&gt; Sue
                [lastName] =&gt; Miller
            )

    )
</code></pre>

<p><code>print_r</code> of $differentArray outputs this:<br/></p>

<pre><code>        Array
    (
            [0] =&gt; Array
                    (
                            [date] =&gt; 1363800434868
                            [userId] =&gt; ID Object
                                    (
                                            [_unknown:protected] =&gt; 
                                            [id_:protected] =&gt; 8k6Y4FTrnxKY45XrVkXvVJhL
                                    )

                            [someTxt] =&gt; aaaa
                    )

            [1] =&gt; Array
                    (
                            [date] =&gt; 1363800858828
                            [userId] =&gt; ID Object
                                    (
                                            [_unknown:protected] =&gt; 
                                            [id_:protected] =&gt; 8k6Y4FTrnxKY45XrVkXvVJhL
                                    )

                            [someTxt] =&gt; cccc
                    )

            [2] =&gt; Array
                    (
                            [date] =&gt; 1363817564430
                            [userId] =&gt; ID Object
                                    (
                                            [_unknown:protected] =&gt; 
                                            [id_:protected] =&gt; pCvR9qvIgGv8WyejcKmRtGD8
                                    )

                            [someTxt] =&gt; ccc
                    )
    )
</code></pre>

<p><strong>and here is my attempt, but it only outputs Joe Smith<br/>
*</strong> <code>$differentArray</code> is constructed the same way as <code>$userArray</code></p>

<pre><code>    $i = 0;
    while ($i &lt; count($differentArray)){
        $userId = $differentArray[$i]['userId'];
        $key = array_search( $userId, $userArray );
        $firstName = $userArray[$key]['firstName'];
        $lastName = $userArray[$key]['lastName'];
         $i++;
    }
</code></pre>

<p>thank you.</p>
