多维2d数组排序

时间:2014-11-01 22:32:22

标签: php sorting multidimensional-array

这是我的数组:

Array
(
    [0] => Array
        (
            [product_option_id] => 1072
            [option_id] => 5
            [name] => Sizes
            [type] => select
            [option_value] => Array
                (
                    [0] => Array
                        (
                            [product_option_value_id] => 8282
                            [option_value_id] => 57
                            [name] => 10
                            [price] => 
                            [price_prefix] => +
                        )

                    [1] => Array
                        (
                            [product_option_value_id] => 8283
                            [option_value_id] => 58
                            [name] => 11
                            [price] => 
                            [price_prefix] => +
                        )

                    [2] => Array
                        (
                            [product_option_value_id] => 8284
                            [option_value_id] => 59
                            [name] => 12
                            [price] => 
                            [price_prefix] => +
                        )

                    [3] => Array
                        (
                            [product_option_value_id] => 8285
                            [option_value_id] => 60
                            [name] => 13
                            [price] => 
                            [price_prefix] => +
                        )

                    [4] => Array
                        (
                            [product_option_value_id] => 8279
                            [option_value_id] => 61
                            [name] => 7
                            [price] => 
                            [price_prefix] => +
                        )

                    [5] => Array
                        (
                            [product_option_value_id] => 8280
                            [option_value_id] => 62
                            [name] => 8
                            [price] => 
                            [price_prefix] => +
                        )

                    [6] => Array
                        (
                            [product_option_value_id] => 8281
                            [option_value_id] => 63
                            [name] => 9
                            [price] => 
                            [price_prefix] => +
                        )

                )

            [required] => 1
        )

)

是否可以按[option_value] [$ i] [name]排序?所以输出应该是:

Array
(
    [0] => Array
        (
            [product_option_id] => 1072
            [option_id] => 5
            [name] => Sizes
            [type] => select
            [option_value] => Array
                (


                    [0] => Array
                        (
                            [product_option_value_id] => 8279
                            [option_value_id] => 61
                            [name] => 7
                            [price] => 
                            [price_prefix] => +
                        )

                    [1] => Array
                        (
                            [product_option_value_id] => 8280
                            [option_value_id] => 62
                            [name] => 8
                            [price] => 
                            [price_prefix] => +
                        )

                    [2] => Array
                        (
                            [product_option_value_id] => 8281
                            [option_value_id] => 63
                            [name] => 9
                            [price] => 
                            [price_prefix] => +
                        )
                    [3] => Array
                        (
                            [product_option_value_id] => 8282
                            [option_value_id] => 57
                            [name] => 10
                            [price] => 
                            [price_prefix] => +
                        )

                    [4] => Array
                        (
                            [product_option_value_id] => 8283
                            [option_value_id] => 58
                            [name] => 11
                            [price] => 
                            [price_prefix] => +
                        )

                    [5] => Array
                        (
                            [product_option_value_id] => 8284
                            [option_value_id] => 59
                            [name] => 12
                            [price] => 
                            [price_prefix] => +
                        )

                    [6] => Array
                        (
                            [product_option_value_id] => 8285
                            [option_value_id] => 60
                            [name] => 13
                            [price] => 
                            [price_prefix] => +
                        )

                )

            [required] => 1
        )

)

我在这方面失去了很多时间,如果有人可以,请帮助我(尝试使用array_multisort但没有结果)

1 个答案:

答案 0 :(得分:0)

{p <1}}需要

PHP&gt; = 5.5.0或使用PHP Implementation of array_column()

array_column()