我对 CI 不是很友好,但这里有一些关于普通 PHP 的代码,我相信它们可以很容易地适应 CI。
$someArray = array();
$someArray[] = array("477205", "2", "6136", "48915", "2013-03-21 00:00:00");
$someArray[] = array("477206", "2", "6134", "48915", "2013-03-21 00:00:00");
$someArray[] = array("477204", "2", "976", "48915", "2013-03-21 00:00:00");
$someArray[] = array("477202", "2", "6136", "48918", "2013-03-15 00:00:00");
$someArray[] = array("477203", "2", "6135", "48914", "2013-03-15 00:00:00");
$someArray[] = array("477202", "2", "6136", "48914", "2013-03-15 00:00:00");
$someArray[] = array("477200", "2", "976", "48913", "2013-03-15 00:00:00");
$someArray[] = array("477201", "2", "6134", "48913", "2013-03-15 00:00:00");
$someArray[] = array("477192", "2", "5497", "48912", "2013-03-14 00:00:00");
$someArray[] = array("477191", "2", "887", "48912", "2013-03-14 00:00:00");
$someArray[] = array("477190", "2", "857", "48912", "2013-03-14 00:00:00");
function CalcUnique($arr,$prop,$val) {
reset ($arr);
$count = 0;
foreach ($arr as $sub) if ($sub[$prop]==$val) $count++;
return $count;
}
echo "<table border=1>\n"; // starting table
$doMerge = $actualVal = false; // setting initial values
foreach ($someArray as $row) { // inerating array
if ($row[3]!=$actualVal) { // if value changed from previous
$mergeNum = CalcUnique($someArray,3,$row[3]); // check if there is more then one row with this value
$actualVal = $row[3]; // store new val
$doMerge = true; // setting flag to merge cells
}
echo "<tr>\n\t<td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td>";
if ($doMerge && $mergeNum>1) { // prints out merged cell
echo "<td rowspan=".$mergeNum.">".$row[3]."</td>";
$doMerge = false;
}
if ($mergeNum==1) echo "<td>".$row[3]."</td>"; // prints out regular cell
echo "<td>".$row[4]."</td>\n";
echo "</tr>\n";
}
echo "</table>";
?>