Delete duplicate php array [duplicate]

1

I have an array like this:

Array
(
    [0] => Array
        (
            [iataCity] => NRT
            [nameCity] => Tokyo
        )

[1] => Array
    (
        [iataCity] => MIA
        [nameCity] => Miami
    )

[2] => Array
    (
        [iataCity] => DFW
        [nameCity] => Dallas
    )

[3] => Array
    (
        [iataCity] => LAX
        [nameCity] => Los Angeles
    )

[4] => Array
    (
        [iataCity] => MIA
        [nameCity] => Miami
    )

)

Miami is repeated, the idea is that no city repeats itself, I have tried with array_unique but it does not work.

I have used the following:

array_unique($flightScales, SORT_REGULAR);
array_unique($flightScales);
array_values(array_unique($flightScales));

Any other ideas?

    
asked by Lina Cortés 18.12.2018 в 16:35
source

1 answer

1

The detail is that you have an array of array (multidimensional), to eliminate a repeated element that in this case is an array use the following:

 $sinReperir = array_map("unserialize", array_unique(array_map("serialize", $flightScales)));
//imprime resultado
print_r($sinReperir);
    
answered by 18.12.2018 / 16:45
source