我正在从 sql server 检索数据,然后以有组织的方式呈现它们。
我有一个这样的对象数组:
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 时,我总是遇到这样的事情。
有什么方便的方法可以做到这一点吗?