note 28892 deleted from function.array-unique by cmb

From: Date: Sun, 27 Oct 2019 08:44:19 +0000
Subject: note 28892 deleted from function.array-unique by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212804@lists.php.net to get a copy of this message
Note Submitter: martin at lucas-smith dot co dot uk ---- To get a list of the duplicated values in an array, array_unique isn't much help. Instead, use array_filter in conjunction with a callback function, as below: <?php $checkKeysUniqueComparison = create_function('$value','if ($value > 1) return true;'); $result = array_keys (array_filter (array_count_values($array), $checkKeysUniqueComparison)); ?> These two lines therefore will create $result, an array of duplicated values in the array $array, once each. E.g. the array $array = array ("a", "b", "a", "b", "x", "y", "z", "x"); gives the result Array([0] => a [1] => b [2] => x)

« previous php.notes (#212804) next »