sorting – rearrange array according to id


I cannot figure out how to regroup this array accourding to ids.

This array comes from a mysql table. the number 17 and 20 are foreign keys in the table.

$orginal_arr => Array
(
(0) => Array
(
(17) => string…?
)

        (1) => Array
            (
                (20) => hello
            )

        (2) => Array
            (
                (20) => string...?
            )

        (3) => Array
            (
                (20) => string... string...??
            )

        (4) => Array
            (
                (17) => string...
            )

        (5) => Array
            (
                (17) => string...
            )

    )

I want to convert the above array into the following:

$desired_arr => Array
(
(0) => Array
(
(17) => Array
(
(0) => string…?
)

            )

        (1) => Array
            (
                (20) => Array
                    (
                        (0) => hello
                        (1) => string...?
                        (2) => string... string...??
                    )

            )

        (2) => Array
            (
                (17) => Array
                    (
                        (0) => string...
                        (1) => string...
                    )

            )

    )

Thank you very much.