note 36636 deleted from function.array-unique by danbrown
| From: | danbrown@php.net | Date: | Sun, 23 Jan 2011 17:25:43 +0000 |
| Subject: | note 36636 deleted from function.array-unique by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176201@lists.php.net to get a copy of this message | ||
Note Submitter: tru at ascribedata dot com
----
Here's a function to make a multi-dimensional array have only DISTINCT values for a certain
"column". It's like using the DISTINCT parameter on a SELECT sql statement.
<?php
function unique_multi_array($array, $sub_key) {
$target = array();
$existing_sub_key_values = array();
foreach ($array as $key=>$sub_array) {
if (!in_array($sub_array[$sub_key], $existing_sub_key_values)) {
$existing_sub_key_values[] = $sub_array[$sub_key];
$target[$key] = $sub_array;
}
}
return $target;
}
?>