テーブルに簡(jiǎn)単なカレンダー設(shè)定trとtdを作成するPHP開(kāi)発
描畫(huà)メソッドを設(shè)定し、テーブルを描畫(huà)し、テーブルにtrとtdを設(shè)定します
1)tableタグを使ってデータを表示するので、ここで各trの下にtdを配置する必要があります
2 )$index % 7 = = 0 テーブルの各行の最初の列を計(jì)算します
3)$index % 7 == 6 || $index == ($length-1) 各行の最後の列を計(jì)算します、または$caculateの最後のデータ
4 )各行の配列である$trに真ん中の行を追加
<?php function draw($caculate) { //$caculate 通過(guò)caculate方法計(jì)算后的數(shù)據(jù) $tr = array(); $length = count($caculate); $result = array(); foreach ($caculate as $index => $date) { if($index % 7 == 0) {//第一列 $tr = array($date); }elseif($index % 7 == 6 || $index == ($length-1)) { array_push($tr, $date); array_push($result, $tr);//添加到返回的數(shù)據(jù)中 $tr = array();//清空數(shù)組列表 }else { array_push($tr, $date); } } return $result; } ?>