来自多维数组的{php}唯一值

时间:2017-05-15 17:05:57

标签: php arrays multidimensional-array unique

我很努力'使用以下数组来检索唯一值。该数组来自嵌套产品组装结构。尝试了几种技术,但还没有结果。 也许有人可以帮我这个? 提前谢谢!


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
    )

)

目标是检索一个数组,如:

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

1 个答案:

答案 0 :(得分:1)

最简单的可能是提取数据索引product_ID,因为索引是唯一的:

$result = array_column($array, null, 'product_ID');