note 36636 added to function.array-unique

From: Date: Thu, 16 Oct 2003 20:40:16 +0000
Subject: note 36636 added to function.array-unique
Groups: php.notes 
Request: Send a blank email to php-notes+get-58719@lists.php.net to get a copy of this message
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. 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; } ---- Manual Page -- http://www.php.net/manual/en/function.array-unique.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36636 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36636&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36636&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#58719) next »