Array
(
[25p] => Array
(
[0] => Array
(
[id] => 353
[label] => C81
[casting] => 21 Mar 2017
[data] => Array
(
[0] => Array
(
[x] => 1
[y] => 6.220000
)
[1] => Array
(
[x] => 2
[y] => 10.220000
)
[2] => Array
(
[x] => 7
[y] => 21.440000
)
[3] => Array
(
[x] => 28
[y] => 30.780000
)
)
)
[1] => Array
(
[id] => 354
[label] => C82
[casting] => 21 Mar 2017
[data] => Array
(
[0] => Array
(
[x] => 1
[y] => 8.000000
)
[1] => Array
(
[x] => 3
[y] => 20.890000
)
[2] => Array
(
[x] => 6
[y] => 30.670000
)
[3] => Array
(
[x] => 7
[y] => 32.555000
)
[4] => Array
(
[x] => 28
[y] => 51.110000
)
)
)
[2] => Array
(
[id] => 355
[label] => C83
[casting] => 21 Mar 2017
[data] => Array
(
[0] => Array
(
[x] => 1
[y] => 7.110000
)
[1] => Array
(
[x] => 3
[y] => 19.780000
)
[2] => Array
(
[x] => 6
[y] => 23.560000
)
[3] => Array
(
[x] => 7
[y] => 32.225000
)
[4] => Array
(
[x] => 15
[y] => 38.890000
)
)
)
[age] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 6
[4] => 7
[5] => 15
[6] => 28
)
)
)
我想創建一個基於[age]
值的表作爲標題。我設法創建了表格,但問題是,我的數據未正確放置。 [age]
基於[data][x]
值的唯一平坦列表。從陣列中的數據,C83
不應該有數據爲2D,因爲下面沒有[data][x] = 2
從不同長度和值的數組創建表php
+---------------+----------+-----------+-----------+-----------+-----------+-----+-----+
| Monitor Label | 1D | 2D | 3D | 6D | 7D | 15D | 28D |
+---------------+----------+-----------+-----------+-----------+-----------+-----+-----+
| C81 | 6.220000 | 10.220000 | 21.440000 | 30.780000 | |
| |
| C82 | 8.000000 | 20.890000 | 30.670000 | 32.555000 | 51.110000 |
| |
| C83 | 7.110000 | 19.780000 | 23.560000 | 32.225000 | 38.890000 |
| |
+---------------+----------+-----------+-----------+-----------+-----------+-----+-----+
是我的代碼生成以上
//test creating HTML
foreach($graph as $grade => $data)
{
echo '<strong>'.strtoupper($grade).'</strong></br>';
//start the table for each grade
echo '<table border=1>';
echo '<thead>';
echo '<tr>';
echo '<th>Monitor Label</th>';
for($i=0;$i < count($data['age']);$i++)
{
echo '<th>'.$data['age'][$i].'D</th>';
}
echo '</tr>';
echo '</thead>';
echo '<tbody>';
for ($i=0;$i < count($data)-1; $i++)
{
echo '<tr>';
echo '<td>'.$data[$i]['label'].'</td>';
foreach($data[$i]['data'] as $x)
{
echo '<td>'.$x['y'].'</td>';
}
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
}
表的一些[data][y]
應該是失蹤,我想更換它帶有 - (短劃線)或#NA,但它只是填充表格列。
如果有人有興趣的數據,這裏是實際的數據串行
a:4:{s:3:"30n";a:2:{i:0;a:4:{s:2:"id";i:423;s:5:"label";s:3:"D43";s:7:"casting";s:11:"05 Apr 2017";s:4:"data";a:5:{i:0;a:2:{s:1:"x";i:1;s:1:"y";s:8:"7.330000";}i:1;a:2:{s:1:"x";i:2;s:1:"y";s:9:"13.560000";}i:2;a:2:{s:1:"x";i:3;s:1:"y";s:9:"16.890000";}i:3;a:2:{s:1:"x";i:7;s:1:"y";s:9:"38.000000";}i:4;a:2:{s:1:"x";i:27;s:1:"y";s:9:"32.670000";}}}s:3:"age";a:5:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:7;i:4;i:27;}}s:3:"30p";a:5:{i:0;a:4:{s:2:"id";i:428;s:5:"label";s:3:"D48";s:7:"casting";s:11:"05 Apr 2017";s:4:"data";a:5:{i:0;a:2:{s:1:"x";i:1;s:1:"y";s:8:"8.000000";}i:1;a:2:{s:1:"x";i:2;s:1:"y";s:9:"15.560000";}i:2;a:2:{s:1:"x";i:3;s:1:"y";s:9:"20.670000";}i:3;a:2:{s:1:"x";i:7;s:1:"y";s:9:"30.440000";}i:4;a:2:{s:1:"x";i:27;s:1:"y";s:9:"42.885000";}}}i:1;a:4:{s:2:"id";i:238;s:5:"label";s:3:"a70";s:7:"casting";s:11:"23 Jan 2017";s:4:"data";a:5:{i:0;a:2:{s:1:"x";i:1;s:1:"y";s:8:"9.560000";}i:1;a:2:{s:1:"x";i:3;s:1:"y";s:9:"18.890000";}i:2;a:2:{s:1:"x";i:4;s:1:"y";s:9:"22.890000";}i:3;a:2:{s:1:"x";i:8;s:1:"y";s:9:"31.775000";}i:4;a:2:{s:1:"x";i:28;s:1:"y";s:9:"40.220000";}}}i:2;a:4:{s:2:"id";i:240;s:5:"label";s:3:"a72";s:7:"casting";s:11:"23 Jan 2017";s:4:"data";a:6:{i:0;a:2:{s:1:"x";i:1;s:1:"y";s:8:"9.330000";}i:1;a:2:{s:1:"x";i:2;s:1:"y";s:9:"16.000000";}i:2;a:2:{s:1:"x";i:3;s:1:"y";s:9:"21.560000";}i:3;a:2:{s:1:"x";i:8;s:1:"y";s:9:"34.890000";}i:4;a:2:{s:1:"x";i:28;s:1:"y";s:9:"46.000000";}i:5;a:2:{s:1:"x";i:31;s:1:"y";s:9:"52.220000";}}}i:3;a:4:{s:2:"id";i:235;s:5:"label";s:3:"a68";s:7:"casting";s:11:"21 Jan 2017";s:4:"data";a:4:{i:0;a:2:{s:1:"x";i:2;s:1:"y";s:8:"7.560000";}i:1;a:2:{s:1:"x";i:4;s:1:"y";s:9:"15.560000";}i:2;a:2:{s:1:"x";i:10;s:1:"y";s:9:"23.890000";}i:3;a:2:{s:1:"x";i:28;s:1:"y";s:9:"32.440000";}}}s:3:"age";a:10:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:7;i:5;i:8;i:6;i:10;i:7;i:27;i:8;i:28;i:9;i:31;}}s:3:"35p";a:5:{i:0;a:4:{s:2:"id";i:424;s:5:"label";s:3:"D44";s:7:"casting";s:11:"05 Apr 2017";s:4:"data";a:5:{i:0;a:2:{s:1:"x";i:1;s:1:"y";s:8:"8.670000";}i:1;a:2:{s:1:"x";i:2;s:1:"y";s:8:"9.560000";}i:2;a:2:{s:1:"x";i:3;s:1:"y";s:9:"18.440000";}i:3;a:2:{s:1:"x";i:7;s:1:"y";s:9:"33.110000";}i:4;a:2:{s:1:"x";i:27;s:1:"y";s:9:"40.335000";}}}i:1;a:4:{s:2:"id";i:425;s:5:"label";s:3:"D45";s:7:"casting";s:11:"05 Apr 2017";s:4:"data";a:5:{i:0;a:2:{s:1:"x";i:1;s:1:"y";s:8:"8.890000";}i:1;a:2:{s:1:"x";i:2;s:1:"y";s:9:"19.560000";}i:2;a:2:{s:1:"x";i:3;s:1:"y";s:9:"26.890000";}i:3;a:2:{s:1:"x";i:7;s:1:"y";s:9:"39.780000";}i:4;a:2:{s:1:"x";i:27;s:1:"y";s:9:"49.445000";}}}i:2;a:4:{s:2:"id";i:426;s:5:"label";s:3:"D46";s:7:"casting";s:11:"05 Apr 2017";s:4:"data";a:5:{i:0;a:2:{s:1:"x";i:1;s:1:"y";s:8:"6.670000";}i:1;a:2:{s:1:"x";i:2;s:1:"y";s:9:"16.440000";}i:2;a:2:{s:1:"x";i:3;s:1:"y";s:9:"16.440000";}i:3;a:2:{s:1:"x";i:7;s:1:"y";s:9:"26.670000";}i:4;a:2:{s:1:"x";i:29;s:1:"y";s:9:"40.670000";}}}i:3;a:4:{s:2:"id";i:269;s:5:"label";s:4:"NS23";s:7:"casting";s:11:"01 Feb 2017";s:4:"data";a:3:{i:0;a:2:{s:1:"x";i:1;s:1:"y";s:8:"6.670000";}i:1;a:2:{s:1:"x";i:5;s:1:"y";s:9:"21.780000";}i:2;a:2:{s:1:"x";i:7;s:1:"y";s:9:"26.000000";}}}s:3:"age";a:7:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:5;i:4;i:7;i:5;i:27;i:6;i:29;}}s:3:"45p";a:3:{i:0;a:4:{s:2:"id";i:233;s:5:"label";s:3:"A65";s:7:"casting";s:11:"21 Jan 2017";s:4:"data";a:4:{i:0;a:2:{s:1:"x";i:2;s:1:"y";s:9:"15.110000";}i:1;a:2:{s:1:"x";i:5;s:1:"y";s:9:"32.440000";}i:2;a:2:{s:1:"x";i:10;s:1:"y";s:9:"44.665000";}i:3;a:2:{s:1:"x";i:28;s:1:"y";s:9:"55.483333";}}}i:1;a:4:{s:2:"id";i:234;s:5:"label";s:3:"a66";s:7:"casting";s:11:"21 Jan 2017";s:4:"data";a:4:{i:0;a:2:{s:1:"x";i:2;s:1:"y";s:9:"14.220000";}i:1;a:2:{s:1:"x";i:5;s:1:"y";s:9:"33.780000";}i:2;a:2:{s:1:"x";i:10;s:1:"y";s:9:"44.780000";}i:3;a:2:{s:1:"x";i:28;s:1:"y";s:9:"55.560000";}}}s:3:"age";a:4:{i:0;i:2;i:1;i:5;i:2;i:10;i:3;i:28;}}}
填這張表中有很多空值 – zimorok