note 103195 deleted from function.array-unique by sobak

From: Date: Sun, 11 Dec 2016 06:54:24 +0000
Subject: note 103195 deleted from function.array-unique by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208483@lists.php.net to get a copy of this message
Note Submitter: mykelscappin at gmail dot com ---- I made an array_unique function to handle deep arrays: <?php function array_unique_deep($array) { $values=array(); //ideally there would be some is_array() testing for $array here... foreach ($array as $part) { if (is_array($part)) $values=array_merge($values,array_unique_deep($part)); else $values[]=$part; } return array_unique($values); } $test=array(123,456,array(789,123,array(456),789),array(123)); print_r(array_unique_deep($test)); ?> outputs Array ( [0] => 123 [1] => 456 [2] => 789 )

« previous php.notes (#208483) next »