How can I convert array of ungrouped items to array of grouped objects?
<p>I need some help converting the following source array to the specified destination array using PHP. How can I do this?</p>

<p><strong>Source Array:</strong></p>

<pre><code>Array
(
    [0] =&gt; Array
        (
            [From] =&gt; SFO

            [To] =&gt; NYC

            [Flight] =&gt; 123
        )

    [1] =&gt; Array
        (
            [From] =&gt; Boston

            [To] =&gt; Seattle

            [Flight] =&gt; 678

        )

    [2] =&gt; Array
    (
        [From] =&gt; Boston

        [To] =&gt; Seattle

        [Flight] =&gt; 789
    )

    [3] =&gt; Array
    (
        [From] =&gt; SFO

        [To] =&gt; NYC

        [Flight] =&gt; 456
    )   
)
</code></pre>

<p><strong>Destination Array:</strong></p>

<pre><code>Array
(
    [0] =&gt; stdClass Object
        (
            [from] =&gt; SFO
            [to] =&gt; NYC
            [directions] =&gt; Array
                (
                    [0] =&gt; stdClass Object
                        (
                            [from] =&gt; SFO
                            [to] =&gt; NYC
                            [flight] =&gt; 123
                        )
                    [1] =&gt; stdClass Object
                    (
                        [from] =&gt; SFO
                        [to] =&gt; NYC
                        [flight] =&gt; 456
                    )

                )

        )

    [1] =&gt; stdClass Object
        (
            [from] =&gt; Boston
            [to] =&gt; Seattle
            [directions] =&gt; Array
                (
                    [0] =&gt; stdClass Object
                        (
                            [from] =&gt; Boston
                            [to] =&gt; Seattle
                            [flight] =&gt; 678
                        )
                    [1] =&gt; stdClass Object
                    (
                        [from] =&gt; Boston
                        [to] =&gt; Seattle
                        [flight] =&gt; 789
                    )   
                )

        )

)
</code></pre>
