note 68157 added to function.array-unique
| From: | uditsawhney at yahoo dot com | Date: | Sat, 15 Jul 2006 19:14:54 +0000 |
| Subject: | note 68157 added to function.array-unique | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-114809@lists.php.net to get a copy of this message | ||
<?php
//Fn for array_unique column-wise for multi-dimensioanl array without losing keys | Start
function array_uniquecolumn($arr)
{
$rows = sizeof($arr);
$columns = sizeof($arr[0]);
$columnkeys = array_keys($arr[0]);
for($i=0; $i<$columns; $i++)
{
for($j=0;$j<$rows;$j++)
{
for($k = $j+1; $k<$rows; $k++)
{
if($arr[$j][$columnkeys[$i]] == $arr[$k][$columnkeys[$i]])
$arr[$k][$columnkeys[$i]] = "";
}
}
}
return ($arr);
}
//Fn for array_unique column-wise for multi-dimensioanl array without losing keys | Stop
$arrUGCourse[]= array( "CTR" => "1",
"UGCOURSE"=>"ABC",
"TSINITIATE"=>"540",
"COUNT"=>"34",
"ENTRY_DT"=>"2006-05-01",
"CUMULATIVE"=> 44);
$arrUGCourse[]= array( "CTR" => "2",
"UGCOURSE"=>"ABC",
"TSINITIATE"=>"5401",
"COUNT"=>"341",
"ENTRY_DT"=>"2006-05-11",
"CUMULATIVE"=> 44);
print_r(array_uniquecolumn($arrUGCourse));
?>
----
Server IP: 203.199.107.94
Probable Submitter: 125.23.51.59
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.array-unique.php
Edit -- http://master.php.net/note/edit/68157
Del: integrated -- http://master.php.net/note/delete/68157/integrated
Del: useless -- http://master.php.net/note/delete/68157/useless
Del: bad code -- http://master.php.net/note/delete/68157/bad+code
Del: spam -- http://master.php.net/note/delete/68157/spam
Del: non-english -- http://master.php.net/note/delete/68157/non-english
Del: in docs -- http://master.php.net/note/delete/68157/in+docs
Del: other reasons-- http://master.php.net/note/delete/68157
Reject -- http://master.php.net/note/reject/68157
Search -- http://master.php.net/manage/user-notes.php