1

I have a big array like this this one (only 5 entries here)

Array
(
    [1] => Array
        (
            [last_token] => atokenforexample
            [idmembre] => 31800
            [key] => 821fbe3f4623649562f75a3de132c908
            [idmembre_mobile] => 230106
        )

    [2] => Array
        (
            [last_token] => atoken1
            [idmembre] => 83586
            [key] => 0854ea148c95c08a30c623a313e645a9
            [idmembre_mobile] => 126634
        )

    [3] => Array
        (
            [last_token] => atoken1
            [idmembre] => 138727
            [key] => 622c0803a8f662c1df852001017b5db8
            [idmembre_mobile] => 119326
        )

    [4] => Array
        (
            [last_token] => atokensocool
            [idmembre] => 163737
            [key] => 8bab884bf46c14abfceaef7abcdf14f9
            [idmembre_mobile] => 222066
        )

    [5] => Array
        (
            [last_token] => WOWanothetoken
            [idmembre] => 236345
            [key] => 41c17896091d9417b305e70541039249

I need to get a unique array from this on only one column, the last_token : So here i need to swipe the array with key 3 (array[3]) because his last_token is the same as array[2][last_token].

Array unique can't work here.. :(

Christopher-BZC
  • 155
  • 1
  • 7

1 Answers1

1

To save the last occurrence:

foreach($array as $value) {
    $result[$value['last_token']] = $value;
}
$result = array_values($result);

Or to save the first occurrence:

foreach(array_reverse($array) as $value) {
    $result[$value['last_token']] = $value;
}
$result = array_reverse(array_values($result));

Probably a more elegant way but I'm starving and off to eat.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87