|
Posted by lorento on 02/13/07 03:46
<?php
$records = array(
array('product' => '30 year','rate'=> 6.0, 'ProgramID' =>9514),
array('product' => '30 year','rate'=> 6.0, 'ProgramID' =>9514),
array('product' => '30 year','rate'=> 6.0, 'ProgramID' =>9517),
array('product' => 'Pay option','rate'=> 1.0, 'ProgramID' =>9513),
array('product' => 'Pay option','rate'=> 1.0, 'ProgramID' =>9513));
function remove_dups($array, $row_element) {
$new_array[0] = $array[0];
foreach ($array as $current) {
$add_flag = 1;
foreach ($new_array as $tmp) {
if ($current[$row_element]==$tmp[$row_element]) {
$add_flag = 0; break;
}
}
if ($add_flag) $new_array[] = $current;
}
return $new_array;
} // end function remove_dups
$a = remove_dups($records, 'ProgramID') ;
print_r ($a);
?>
Original function come from here: http://id2.php.net/manual/tw/
function.array-unique.php
--
http://ascii.mastervb.net - ASCII Art Generator
http://anagram.mastervb.net - Anagram Generator
http://www.mastervb.net/phpbooks - Best PHP Books
On Feb 13, 8:15 am, "Chuy08" <chu...@yahoo.com> wrote:
> If I have a multdimensional array like so:
>
> $records = array(
> array('product' => '30 year','rate'=> 6.0 'ProgramID' =>9514),
> array('product' => '30 year','rate'=> 6.0 'ProgramID' =>9514),
> array('product' => '30 year','rate'=> 6.0 'ProgramID' =>9517),
> array('product' => 'Pay option','rate'=> 1.0 'ProgramID' =>9513),
> array('product' => 'Pay option','rate'=> 1.0 'ProgramID' =>9513));
>
> How could I iterate through this and removing only values that are
> duplicated by ProgramID. In this example the new array should contain only
> the 1st, 3rd and 4th values. Any help appreciated.
>
> chuy
>
> --
> Posted via a free Usenet account fromhttp://www.teranews.com
Navigation:
[Reply to this message]
|