按值对数组进行多维排序

时间:2017-09-03 16:29:21

标签: php arrays sorting multidimensional-array

所以,我有这个数组(下面),并且在使用foreach从 query_collumns 中提取值时,我想按 query_collumn_order 进行升序排序。

我正在寻找一个简单而优雅的解决方案。 如果可能的话,我不想重组,以任何其他方式重新生成数组。

怎么样?

提前谢谢大家。

Array
(
    [query_id] => 1
    [query_name] => test
    [query_database] => qwe
    [query_main_table] => query
    [query_main_collumn] => query_id
    [query_join] => 
    [query_filter] => 
    [query_orderby] => 
    [query_collumns] => Array
        (
            [1] => Array
                (
                    [query_collumn_id] => 1
                    [query_collumn_name] => query_id
                    [query_collumn_order] => 1
                    [query_collumn_width] => 0
                    [query_collumn_visible] => 0
                    [query_collumn_query_id] => 1
                    [query_collumn_user_setting_user_id] => 
                    [query_collumn_user_setting_filter_type] => 
                    [query_collumn_user_setting_filter_value] => 
                )

            [2] => Array
                (
                    [query_collumn_id] => 2
                    [query_collumn_name] => query_name
                    [query_collumn_order] => 4
                    [query_collumn_width] => 1
                    [query_collumn_visible] => 1
                    [query_collumn_query_id] => 1
                    [query_collumn_user_setting_user_id] => 1
                    [query_collumn_user_setting_filter_type] => 
                    [query_collumn_user_setting_filter_value] => 
                )

            [3] => Array
                (
                    [query_collumn_id] => 3
                    [query_collumn_name] => query_database
                    [query_collumn_order] => 3
                    [query_collumn_width] => 0
                    [query_collumn_visible] => 0
                    [query_collumn_query_id] => 1
                    [query_collumn_user_setting_user_id] => 
                    [query_collumn_user_setting_filter_type] => 
                    [query_collumn_user_setting_filter_value] => 
                )

        )

)

1 个答案:

答案 0 :(得分:0)

将ifnull()与ORDER BY一起使用解决了我的问题。基本上,使用正确的顺序生成数组,并且不再需要后期排序。