samedi 27 juin 2015

formatting an array using php

I have the following array which have duplicate data:

Array
(
    [0] => Array
        (
            [orders] => Array
                (
                    [id] => 9
                    [name] => Abdus Sattar Bhuiyan
                    [email] => sattar.kuet@gmail.com
                    [mobile] => 01673050495
                    [alt_mobile] => 01818953250
                    [city_id] => 2
                    [location_id] => 5
                    [status] => No contact
                    [chashed] => NO
                    [created] => 2015-06-27 12:49:34
                    [modified] => 2015-06-27 12:49:34
                    [comment] => 
                )

            [order_products] => Array
                (
                    [id] => 2
                    [order_id] => 9
                    [product_id] => 1
                    [pieces] => 1
                )

            [products] => Array
                (
                    [id] => 1
                    [category_id] => 1
                    [name] => নভোযানের নাম সি প্রোগ্রামিং
                    [writer] => Engr. Abdus Sattar Bhuiyan
                    [created] => 2015-06-24 16:17:45
                )

            [psettings] => Array
                (
                    [id] => 1
                    [category_id] => 1
                    [product_id] => 1
                    [img] => 1.jpg
                    [desc] => description
                    [created] => 2015-06-28 00:28:26
                    [bppp] => 44000
                    [sppp] => 45000
                    [discount] => 25
                    [service_charge] => 30
                )

        )

    [1] => Array
        (
            [orders] => Array
                (
                    [id] => 9
                    [name] => Abdus Sattar Bhuiyan
                    [email] => sattar.kuet@gmail.com
                    [mobile] => 01673050495
                    [alt_mobile] => 01818953250
                    [city_id] => 2
                    [location_id] => 5
                    [status] => No contact
                    [chashed] => NO
                    [created] => 2015-06-27 12:49:34
                    [modified] => 2015-06-27 12:49:34
                    [comment] => 
                )

            [order_products] => Array
                (
                    [id] => 3
                    [order_id] => 9
                    [product_id] => 2
                    [pieces] => 1
                )

            [products] => Array
                (
                    [id] => 2
                    [category_id] => 1
                    [name] => Resonance of creativity with C++
                    [writer] => Engr. Abdus Sattar Bhuiyan
                    [created] => 2015-06-26 07:32:52
                )

            [psettings] => Array
                (
                    [id] => 2
                    [category_id] => 1
                    [product_id] => 2
                    [img] => 2.jpg
                    [desc] => 
                    [created] => 2015-06-26 07:33:41
                    [bppp] => 150
                    [sppp] => 250
                    [discount] => 20
                    [service_charge] => 30
                )

        )

    [2] => Array
        (
            [orders] => Array
                (
                    [id] => 9
                    [name] => Abdus Sattar Bhuiyan
                    [email] => sattar.kuet@gmail.com
                    [mobile] => 01673050495
                    [alt_mobile] => 01818953250
                    [city_id] => 2
                    [location_id] => 5
                    [status] => No contact
                    [chashed] => NO
                    [created] => 2015-06-27 12:49:34
                    [modified] => 2015-06-27 12:49:34
                    [comment] => 
                )

            [order_products] => Array
                (
                    [id] => 4
                    [order_id] => 9
                    [product_id] => 3
                    [pieces] => 1
                )

            [products] => Array
                (
                    [id] => 3
                    [category_id] => 1
                    [name] => programming by story C
                    [writer] => Hasibul Hasan Shanto
                    [created] => 2015-06-26 07:35:57
                )

            [psettings] => Array
                (
                    [id] => 3
                    [category_id] => 1
                    [product_id] => 3
                    [img] => 3.jpg
                    [desc] => 
                    [created] => 2015-06-26 07:36:26
                    [bppp] => 150
                    [sppp] => 250
                    [discount] => 10
                    [service_charge] => 30
                )

        )

)

I want to format this array and produce the following array:

Array
(
    [0] => Array
        (
            [orders] => Array
                (
                    [id] => 9
                    [name] => Abdus Sattar Bhuiyan
                    [email] => sattar.kuet@gmail.com
                    [mobile] => 01673050495
                    [alt_mobile] => 01818953250
                    [city_id] => 2
                    [location_id] => 5
                    [status] => No contact
                    [chashed] => NO
                    [created] => 2015-06-27 12:49:34
                    [modified] => 2015-06-27 12:49:34
                    [comment] => 
                )
             [order_products] => Array
                            (
                                  [0] => Array(
                                           [id] => 2
                                           [order_id] => 9
                                           [product_id] => 1
                                           [pieces] => 1
                                        )
                                   [1] => Array(
                                           [id] => 3
                                           [order_id] => 9
                                           [product_id] => 2
                                           [pieces] => 1
                                        )   
                                     [2] => Array(
                                          [id] => 4
                                          [order_id] => 9
                                          [product_id] => 3
                                          [pieces] => 1
                                        ) 

                            )

                    [products] => Array
                    (
                          [0] => Array(
                                    [id] => 1
                                    [category_id] => 1
                                    [name] => C programming
                                    [writer] => Engr. Abdus Sattar Bhuiyan
                                    [created] => 2015-06-24 16:17:45
                                )
                           [1] => Array(
                                    [id] => 2
                                    [category_id] => 1
                                    [name] => Resonance of creativity with C++
                                    [writer] => Engr. Abdus Sattar Bhuiyan
                                    [created] => 2015-06-26 07:32:52
                                )   
                             [2] => Array(
                                     [id] => 3
                                    [category_id] => 1
                                    [name] => programming by story C
                                    [writer] => Hasibul Hasan Shanto
                                    [created] => 2015-06-26 07:35:57
                                ) 

                    )     

                    [psettings] => Array
                    (
                          [0] => Array(
                                    [id] => 1
                                    [category_id] => 1
                                    [product_id] => 1
                                    [img] => 1.jpg
                                    [desc] => description
                                    [created] => 2015-06-28 00:28:26
                                    [bppp] => 44000
                                    [sppp] => 45000
                                    [discount] => 25
                                    [service_charge] => 30
                                )
                           [1] => Array(
                                    [id] => 2
                                    [category_id] => 1
                                    [product_id] => 2
                                    [img] => 2.jpg
                                    [desc] => 
                                    [created] => 2015-06-26 07:33:41
                                    [bppp] => 150
                                    [sppp] => 250
                                    [discount] => 20
                                    [service_charge] => 30
                                )   
                             [2] => Array(
                                    [id] => 3
                                    [category_id] => 1
                                    [product_id] => 3
                                    [img] => 3.jpg
                                    [desc] => 
                                    [created] => 2015-06-26 07:36:26
                                    [bppp] => 150
                                    [sppp] => 250
                                    [discount] => 10
                                    [service_charge] => 30
                                ) 

                    ) 
            ) 
    )       

How can I do this. I reformat simple array but this does not make sense to me to format. It makes me cry. Please help me. If any helper function is suggested it will be really a gift. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire