元素数组在php中排序像一棵树

时间:2018-09-14 06:53:53

标签: php arrays

我有一个数组,我需要根据category_level_ids对数组进行排序,

if(jQuery(window).width() < 601px){
    jQuery('.your-div-class').addClass('w-50');
}
else {
    jQuery('.your-div-class').removeClass('w-50');
}

category_level_ids以逗号分隔存储,在此数组category_level_ids中:-[82,1]具有3个标签,[242,1]具有2个标签,依此类推... 我需要以树状结构显示此数组, 我如何像下面这样对数组进行排序:-

                Array
                (
                    [0] => Array
                        (
                            [label_id] => 8
                            [label] => Position
                            [category_level_ids] => 463,462,461
                        )

                    [1] => Array
                        (
                            [label_id] => 13
                            [label] => Voltage
                            [category_level_ids] => 82,1
                        )

                    [2] => Array
                        (
                            [label_id] => 15
                            [label] => Capacity
                            [category_level_ids] => 82,1
                        )                               

                    [3] => Array
                        (
                            [label_id] => 40
                            [label] => Point Type
                            [category_level_ids] => 242,1
                        )

                    [4] => Array
                        (
                            [label_id] => 41
                            [label] => Blade Size
                            [category_level_ids] => 242,1
                        )

                    [5] => Array
                        (
                            [label_id] => 43
                            [label] => No. of Keys
                            [category_level_ids] => 496,494
                        )


                    [6] => Array
                        (
                            [label_id] => 77
                            [label] => Condition
                            [category_level_ids] => 494,0
                        )

                    [7] => Array
                        (
                            [label_id] => 84
                            [label] => Fuel
                            [category_level_ids] => 494,0
                        )

                    [8] => Array
                        (
                            [label_id] => 85
                            [label] => Use
                            [category_level_ids] => 82,1
                        )

                )

0 个答案:

没有答案