How to remove duplicates from multidimensional array in php

Posted by JackTurky on Stack Overflow See other posts from Stack Overflow or by JackTurky
Published on 2012-09-05T15:36:45Z Indexed on 2012/09/05 15:37 UTC
Read the original article Hit count: 178

i have an array like:

Array
(
    [prom] => Array
        (
            [cab] => Array
                (
                    [0] => Array
                        (
                            [code] => 01
                            [price1] => 1000
                            [price2] => 2000
                            [available] => 2
                            [max] => 2
                            [gca] => 2
                        )

                    [1] => Array
                        (
                            [code] => 04
                            [price1] => 870
                            [price2] => 2500
                            [available] => 3
                            [max] => 4
                            [gca] => 10
                        )

                    [2] => Array
                        (
                            [code] => 01
                            [price1] => 1000
                            [price2] => 2000
                            [available] => 2
                            [max] => 2
                            [gca] => 2
                        )

                    [3] => Array
                        (
                            [code] => 05
                            [price1] => 346
                            [price2] => 1022
                            [available] => 10
                            [max] => 2
                            [gca] => 20
                        )

                )
           [cab1] => Array........

        )
    [prom1] = Array....
)

What i have to do is to remove duplicates inside every [cab*] array..

so to have something like:

Array
    (
        [prom] => Array
            (
                [cab] => Array
                    (
                        [0] => Array
                            (
                                [code] => 01
                                [price1] => 1000
                                [price2] => 2000
                                [available] => 2
                                [max] => 2
                                [gca] => 2
                            )

                        [1] => Array
                            (
                                [code] => 04
                                [price1] => 870
                                [price2] => 2500
                                [available] => 3
                                [max] => 4
                                [gca] => 10
                            )

                        [2] => Array
                            (
                                [code] => 05
                                [price1] => 346
                                [price2] => 1022
                                [available] => 10
                                [max] => 2
                                [gca] => 20
                            )

                    )
               [cab1] => Array........

            )
        [prom1] = Array....
    )

In know that there is array_unique combined with array_map to remove duplicates.. but i know that it works only on 2D array.. what can i do? can someone help me pls? thanks!!!

© Stack Overflow or respective owner

Related posts about php

Related posts about multidimensional-array