note 104102 added to function.array-unique
| From: | 0cool dot f at osu1 dot php dot net | Date: | Mon, 23 May 2011 10:54:04 +0000 |
| Subject: | note 104102 added to function.array-unique | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179949@lists.php.net to get a copy of this message | ||
Hope this can help...
<?php
function array_unique_key_group($array) {
if(!is_array($array))
return false;
$temp = array_unique($array);
foreach($array as $key => $val) {
$i = array_search($val,$temp);
if(!empty($i) && $key != $i) {
$temp[$i.','.$key] = $temp[$i];
unset($temp[$i]);
}
}
return $temp;
}
?>
this function return an array that is unique, but preserve every key for the element...
sorry for bad english I'm italian...
$array['asd'] = 'value';
$array['lol'] = 'value';
$array['foo'] = 'val';
$array['bar'] = 'val';
var_dump(array_unique_key_group($array));
// will be output
array(2) { ["asd,lol"]=> string(5) "value" ["foo,bar"]=>
string(3) "val" }
----
Server IP: 69.147.83.197
Probable Submitter: 213.203.153.54
----
Manual Page -- http://www.php.net/manual/en/function.array-unique.php
Edit -- https://master.php.net/note/edit/104102
Del: integrated -- https://master.php.net/note/delete/104102/integrated
Del: useless -- https://master.php.net/note/delete/104102/useless
Del: bad code -- https://master.php.net/note/delete/104102/bad+code
Del: spam -- https://master.php.net/note/delete/104102/spam
Del: non-english -- https://master.php.net/note/delete/104102/non-english
Del: in docs -- https://master.php.net/note/delete/104102/in+docs
Del: other reasons-- https://master.php.net/note/delete/104102
Reject -- https://master.php.net/note/reject/104102
Search -- https://master.php.net/manage/user-notes.php