如何在php中重新安排数组

时间:2015-06-25 10:45:20

标签: php arrays cakephp

Array
(
    [0] => Array
        (
            [Product] => Array
                (
                    [id] => 5
                    [user_id] => 5
                    [category_id] => 1
                    [name] => Suger
                    [weight] => 1
                    [measurement] => kg
                    [image] => 
                    [status] => 1
                    [created] => 2015-05-29 17:02:25
                    [updated] => 0000-00-00 00:00:00
                )

            [Category] => Array
                (
                    [id] => 1
                    [user_id] => 1
                    [category_name] => Daily uses
                    [category_image] => 
                    [status] => 1
                    [created] => 2015-05-25 12:56:10
                    [updated] => 2015-06-25 10:27:40
                )

            [Storeproduct] => Array
                (
                    [0] => Array
                        (
                            [id] => 23
                            [product_id] => 5
                            [store_id] => 2
                            [details] => 
                            [mrp] => 10
                            [selling_price] => 10
                            [discount] => 0
                            [price_difference] => 0
                            [is_deal] => 0
                            [deal_start_date] => 
                            [deal_end_date] => 
                            [status] => 1
                            [created] => 1435055384
                            [updated] => 1435055384
                        )

                    [1] => Array
                        (
                            [id] => 28
                            [product_id] => 5
                            [store_id] => 1
                            [details] => 
                            [mrp] => 10
                            [selling_price] => 10
                            [discount] => 0
                            [price_difference] => 0
                            [is_deal] => 0
                            [deal_start_date] => 
                            [deal_end_date] => 
                            [status] => 1
                            [created] => 1435062129
                            [updated] => 1435062129
                        )

                )

        )

    [1] => Array
        (
            [Product] => Array
                (
                    [id] => 6
                    [user_id] => 1
                    [category_id] => 1
                    [name] => Tea
                    [weight] => 1
                    [measurement] => litre
                    [image] => 
                    [status] => 1
                    [created] => 2015-05-29 17:02:48
                    [updated] => 2015-06-18 18:53:30
                )

            [Category] => Array
                (
                    [id] => 1
                    [user_id] => 1
                    [category_name] => Daily uses
                    [category_image] => 
                    [status] => 1
                    [created] => 2015-05-25 12:56:10
                    [updated] => 2015-06-25 10:27:40
                )

            [Storeproduct] => Array
                (
                    [0] => Array
                        (
                            [id] => 22
                            [product_id] => 6
                            [store_id] => 2
                            [details] => 
                            [mrp] => 10
                            [selling_price] => 10
                            [discount] => 0
                            [price_difference] => 0
                            [is_deal] => 0
                            [deal_start_date] => 
                            [deal_end_date] => 
                            [status] => 1
                            [created] => 1435055076
                            [updated] => 1435055076
                        )

                    [1] => Array
                        (
                            [id] => 25
                            [product_id] => 6
                            [store_id] => 1
                            [details] => 
                            [mrp] => 12
                            [selling_price] => 12
                            [discount] => 0
                            [price_difference] => 0
                            [is_deal] => 0
                            [deal_start_date] => 
                            [deal_end_date] => 
                            [status] => 1
                            [created] => 1435059905
                            [updated] => 1435059905
                        )

                )

        )

    [5] => Array
        (
            [Product] => Array
                (
                    [id] => 11
                    [user_id] => 2
                    [category_id] => 13
                    [name] => Real Mix Fruit Juice
                    [weight] => 200
                    [measurement] => litre
                    [image] => 
                    [status] => 1
                    [created] => 2015-06-17 12:03:19
                    [updated] => 2015-06-18 13:05:16
                )

            [Category] => Array
                (
                    [id] => 13
                    [user_id] => 2
                    [category_name] => Soft Drink juices
                    [category_image] => 
                    [status] => 1
                    [created] => 2015-06-17 11:15:33
                    [updated] => 2015-06-18 18:46:03
                )

            [Storeproduct] => Array
                (
                    [0] => Array
                        (
                            [id] => 2
                            [product_id] => 11
                            [store_id] => 2
                            [details] => Real Mix Fruit Juice(200 litre)
                            [mrp] => 20
                            [selling_price] => 18
                            [discount] => 10
                            [price_difference] => 2
                            [is_deal] => 0
                            [deal_start_date] => 
                            [deal_end_date] => 
                            [status] => 1
                            [created] => 1434613767
                            [updated] => 1434613767
                        )

                    [1] => Array
                        (
                            [id] => 29
                            [product_id] => 11
                            [store_id] => 1
                            [details] => Real Mix Fruit Juice
                            [mrp] => 10
                            [selling_price] => 10
                            [discount] => 0
                            [price_difference] => 0
                            [is_deal] => 0
                            [deal_start_date] => 
                            [deal_end_date] => 
                            [status] => 1
                            [created] => 1435062192
                            [updated] => 1435123348
                        )

                )

        )

    [8] => Array
        (
            [Product] => Array
                (
                    [id] => 14
                    [user_id] => 2
                    [category_id] => 13
                    [name] => Real Apple Juice
                    [weight] => 1
                    [measurement] => ml
                    [image] => 
                    [status] => 1
                    [created] => 2015-06-18 13:06:44
                    [updated] => 0000-00-00 00:00:00
                )

            [Category] => Array
                (
                    [id] => 13
                    [user_id] => 2
                    [category_name] => Soft Drink juices
                    [category_image] => 
                    [status] => 1
                    [created] => 2015-06-17 11:15:33
                    [updated] => 2015-06-18 18:46:03
                )

            [Storeproduct] => Array
                (
                    [0] => Array
                        (
                            [id] => 24
                            [product_id] => 14
                            [store_id] => 2
                            [details] => 
                            [mrp] => 10
                            [selling_price] => 10
                            [discount] => 0
                            [price_difference] => 0
                            [is_deal] => 0
                            [deal_start_date] => 
                            [deal_end_date] => 
                            [status] => 1
                            [created] => 1435055411
                            [updated] => 1435055411
                        )

                )

        )

)

在上面的数组中有两个相同的类别数组。我想合并相同的类别数组记录 我需要像

这样的输出
Category => array(
                 //category data, 
                 Products=>array(//product data,
                                 Storeproducts =>array(
                                                       //Storeproducts data
                                                       )
                                 )
            )

1 个答案:

答案 0 :(得分:0)

PHP已有详细记录,您可以在this page找到所有数组排序方法。

评论中也有一些很好的例子 - 您需要做的就是按类别对数组进行排序,然后就完成了。