PHP组织具有相同值的行
我正在从sql server检索数据,然后以有组织的方式呈现这些数据。PHP组织具有相同值的行,php,mysql,Php,Mysql,我正在从sql server检索数据,然后以有组织的方式呈现这些数据。 我有这样一个对象数组: Array ( [0] => stdClass Object ( [post_id] => 1 [controller] => Cato [controller_method] => edit [http_method] => post ) [1] => stdClass Object
我有这样一个对象数组:
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
)
)
)
)
)
不知何故,我需要转换成这样: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时,我总是遇到类似的情况有什么方便的方法吗?结果数据中的
controller1
和controller2
来自哪里?它们不会出现在输入中的任何位置。另外,除了这个控制器
键外,两个输出数组似乎是相同的,从一种格式到另一种格式的逻辑是什么?我只是举一个例子,实际上控制器列是不同的。每个控制器都有许多控制器方法。每个控制器方法都有许多http\U方法。我需要组织它们。所以输入数据实际上只代表一个控制器?