Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP组织具有相同值的行_Php_Mysql - Fatal编程技术网

PHP组织具有相同值的行

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

我正在从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
                )
            )
        )
    )
)
不知何故,我需要转换成这样:

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方法。我需要组织它们。所以输入数据实际上只代表一个控制器?