开发者

Can array_unique be used for multi dimensional arrays

开发者 https://www.devze.com 2023-01-29 05:51 出处:网络
i just wanted to know whether array_unique be used for m开发者_C百科ulti dimensional arraysFrom the docs:

i just wanted to know whether array_unique be used for m开发者_C百科ulti dimensional arrays


From the docs:

Note that array_unique() is not intended to work on multi dimensional arrays.


From php.net's page on array_unique

Note: Note that array_unique() is not intended to work on multi dimensional arrays


array_unique() is not intended to work on multi dimensional arrays.


just go here http://php.net/manual/en/function.array-unique.php and read this "Note: Note that array_unique() is not intended to work on multi dimensional arrays"


<?php

$array = array(
    array(
        'id'    => 123,
        'name'  => 'Some Product',
        'ean'   => '1234567890123'
    ),
    array(
        'id'    => 123,
        'name'  => 'Some Product',
        'ean'   => '4852950174938'
    ),
    array(
        'id'    => 123,
        'name'  => 'Some Product',
        'ean'   => '1234567890123'
    ),
);
$uniqueArray = array_unique($array);
var_dump($uniqueArray);
?>

Output

array(1) {
  [0]=>
  array(3) {
    ["id"]=>
    int(123)
    ["name"]=>
    string(12) "Some Product"
    ["ean"]=>
    string(13) "1234567890123"
  }
}

Please see that http://php.net/manual/en/function.array-unique.php

0

精彩评论

暂无评论...
验证码 换一张
取 消