2016-02-19 52 views
-1

我有像波紋管的陣列,並且所述陣列中的數據是有點大使HTML表,PHP - 使用2D陣列

Array ([0] => stdClass Object ([ID] => 1 [cyear] => 2016 [cmonth] => 1 [cmonthname] => January [cday] => 1 [cdayname] => Friday [ctime] => 9:00 [status] => 6 [notes] =>) 
     [1] => stdClass Object ([ID] => 2 [cyear] => 2016 [cmonth] => 1 [cmonthname] => January [cday] => 1 [cdayname] => Friday [ctime] => 9:15 [status] => 1 [notes] =>) 
     [2] => stdClass Object ([ID] => 3 [cyear] => 2016 [cmonth] => 1 [cmonthname] => January [cday] => 1 [cdayname] => Friday [ctime] => 9:30 [status] => 1 [notes] =>) 
     [3] => stdClass Object ([ID] => 4 [cyear] => 2016 [cmonth] => 1 [cmonthname] => January [cday] => 1 [cdayname] => Friday [ctime] => 9:45 [status] => 1 [notes] =>) 
     [4] => stdClass Object ([ID] => 5 [cyear] => 2016 [cmonth] => 1 [cmonthname] => January [cday] => 1 [cdayname] => Friday [ctime] => 10:00 [status] => 1 [notes] =>) 
     [5] => stdClass Object ([ID] => 6 [cyear] => 2016 [cmonth] => 1 [cmonthname] => January [cday] => 1 [cdayname] => Friday [ctime] => 10:15 [status] => 1 [notes] =>) 

這背後的想法,

每個陣列代表一個給定時隙(15分鐘)從上午09點到下午5點00

這意味着一小時有04數量的陣列/ stdClass的對象(9:00,9:15,9:30,9:45)

用於一天有32個陣列/ stdCla SS對象上午09時至下午5點00 - >8小時 所以8×4 = 32

所以對於2016年二月,有928(32 * 29)陣列/ stdClass的對象 並且可以

download the full data array here.

使用此我想打一個HTML表格如下圖所示,

enter image description here

綠色行是天(1至2016年29月)

黃色柱是時隙(上午9時00分至下午4時45分)

1S各自陣列的狀態/ stdClass的對象

+1

我在這裏錯過了一個問題嗎? –

+0

我沒有讓你:) –

+0

我不明白這個問題。你在問什麼?如何打印表格? –

回答

1

HTML趨向於更容易進行打印時可以打印水平的,則垂直,所以首先將它放入網格中。

$newArray=[][]; 
foreach($hugeArray as $block) 
    $newArray[$block["ctime"]][$block["cday"]]=$block["status"]; 

現在你可以雙循環打印。 (假設使用表並且排除第一行):

foreach($newArray as $ctime=>$smalArray) 
{ 
    print("<tr><td>".$ctime."</td>"); 
    foreach($smalArray as $cday => $status) 
     print("<td>".$status."</td>"); 
    print("</tr>"); 
} 
+0

謝謝你。爲此欣賞你的手。你的算法正在工作:)) –