0

私はSQLサーバーからデータを取得し、整理して提示しています。
次のようなオブジェクトの配列があります。

Array
(
[0] => stdClass Object
    (
        [post_id] => 1
        [controller] => Cato
        [controller_method] => edit
        [http_method] => post
    )

[1] => stdClass Object
    (
        [post_id] => 1
        [controller] => Cato
        [controller_method] => edit
        [http_method] => get
    )

[2] => stdClass Object
    (
        [post_id] => 1
        [controller] => Cato
        [controller_method] => create
        [http_method] => post
    )

[3] => stdClass Object
    (
        [post_id] => 1
        [controller] => Cato
        [controller_method] => create
        [http_method] => get
    )
)

どういうわけか、次のようなものに変換する必要があります。

Array(
    [0] => Array(
        [controller] => controller1,
        [controller_methods] => Array (
            [0] => Array (
                [controller_method] => create,
                [http_methods] => Array (
                    [0] => get,
                    [1] => post
                )
            ),
            [0] => Array (
                [controller_method] => edit,
                [http_methods] => Array (
                    [0] => get,
                    [1] => post
                )
            )
        )
    ),
    [0] => Array(
        [controller] => controller2,
        [controller_methods] => Array (
            [0] => Array (
                [controller_method] => create,
                [http_methods] => Array (
                    [0] => get,
                    [1] => post
                )
            ),
            [0] => Array (
                [controller_method] => edit,
                [http_methods] => Array (
                    [0] => get,
                    [1] => post
                )
            )
        )
    )
)

SQL db で php を使用していると、いつもこのようなことに遭遇
します。これを行う便利な方法はありますか?

4

0 に答える 0