多次元配列から作った表の重複行をまとめたい
データベースからある期限(14年3月21日から3月30日)で取得した下記の多次元配列から日付に該当するデータがあればセルに値を入れて表を作ったのですが、
<?php
$cal=array(
array("type" => 19, "name" => "山田", "hour" => 5, "day" => 2014-03-21),
array("type" => 19, "name" => "山田", "hour" => 8, "day" => 2014-03-24),
array("type" => 19, "name" => "山田", "hour" => 8, "day" => 2014-03-26),
array("type" => 19, "name" => "田中", "hour" => 8, "day" => 2014-03-23),
array("type" => 19, "name" => "田中", "hour" => 8, "day" => 2014-03-26),
array("type" => 19, "name" => "田中", "hour" => 3, "day" => 2014-03-28),
array("type" => 20, "name" => "大田", "hour" => 3, "day" => 2014-03-21),
array("type" => 20, "name" => "大田", "hour" => 5, "day" => 2014-03-27),
array("type" => 20, "name" => "田中", "hour" => 3, "day" => 2014-03-24),
array("type" => 20, "name" => "田中", "hour" => 4, "day" => 2014-03-27),
array("type" => 0, "name" => "高橋", "hour" => 1, "day" => 2014-03-27),
);
?>
<?php foreach ( $cal as $val ) : ?>
<tr>
<td><?php echo $val['type']; ?></td>
<td><?php echo $val['name']; ?></td>
<?php for ( $i = 21; $i <= 30; $i ++ ) : ?>
<td>
<?php
if ( $day == $i ) {
echo $val['hour'];
}
?>
</td>
<?php endfor; ?>
</tr>
<?php endforeach; ?>
同じIDと名前の行が複数あり、同じIDと名前の行をひとつにしたいのです(画像参照)がわからず質問させていただきました。よろしくお願い致します。