0

I am strugglin' with following array to retreive the unique values. This array comes from a nested product assembly structure. Tried several techniques but no result yet. Maybe someone can help me with this? Thanks in advance!


Array
(
    [0] => Array
        (
            [product_ID] => 1
            [amount] => 2.00
        )

[1] => Array
    (
        [product_ID] => 1
        [amount] => 2.00
    )

[2] => Array
    (
        [product_ID] => 1
        [amount] => 2.00
    )

[3] => Array
    (
        [product_ID] => 5
        [amount] => 6.00
    )

)

Goal is to retreive an array like:

Array
(
    [0] => Array
        (
            [product_ID] => 1
            [amount] => 2.00
        )

[1] => Array
    (
        [product_ID] => 5
        [amount] => 6.00
    )

)

karel
  • 53
  • 6

1 Answers1

1

The simplest may be too extract the array indexing it by product_ID since indexes are unique:

$result = array_column($array, null, 'product_ID');
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
  • Awesome! Here's a slight modification in the event you want to reset the keys after removing the duplicates: array_values( array_column($array, null, 'product_ID') ); – wLc Nov 16 '17 at 21:24