【发布时间】:2016-03-15 08:20:41
【问题描述】:
我有一个像下面这样的数组,
Array ( [0] => stdClass Object ( [projectname] => test p1 [structurename] => test structure [taskname] => task [taskstartdate] => 2016-02-02 00:00:00 [estimatedhours] => 10.00 [hours] => 5.00 [createdon] => 2016-02-03 07:38:08 )
[1] => stdClass Object ( [projectname] => test p1 [structurename] => test structure [taskname] => task [taskstartdate] => 2016-02-02 00:00:00 [estimatedhours] => 10.00 [hours] => 2.00 [createdon] => 2016-02-04 14:21:34 )
[2] => stdClass Object ( [projectname] => p2 [structurename] => struc [taskname] => p2t1 [taskstartdate] => 2016-02-03 00:00:00 [estimatedhours] => 8.00 [hours] => 2.00 [createdon] => 2016-02-04 11:05:31 )
[3] => stdClass Object ( [projectname] => p2 [structurename] => struc [taskname] => p2t1 [taskstartdate] => 2016-02-03 00:00:00 [estimatedhours] => 8.00 [hours] => 6.00 [createdon] => 2016-02-05 08:00:22 )
[4] => stdClass Object ( [projectname] => web dev [structurename] => dev test [taskname] => dev task [taskstartdate] => 2016-02-04 00:00:00 [estimatedhours] => 30.00 [hours] => 8.00 [createdon] => 2016-02-04 08:21:14 ))
和我希望您能帮助我使用上述数组创建以下 HTML 表格输出,
这个想法是显示给定任务在某个周期间(在本例中为 2016 年 2 月的第一周)内的工作时间。 根据上述数组,[hours] 为工作时间,[createdon] 为当天工作时间。
举个例子,
测试 p1 |测试结构 | task - 在上面的 stdClass 对象中有两个数组( [0] => stdClass Object 和 [ 1 ] => stdClass Object ),因为它们代表给定项目的同一个任务,它们应该在 HTML 表中的一行中。
02-01 | 02-02 | 02-03 | 02-04 | 02-05 是日期(二月第一周) 我正在使用另一个数组作为日期如下
Array ( [0] => 2016-02-01
[1] => 2016-02-02
[2] => 2016-02-03
[3] => 2016-02-04
[4] => 2016-02-05 )
我已经尝试如下,但它没有给我预期的输出。
<table id="filter_table4" class="mytable">
<thead>
<tr>
<th>Project | Structure | <b>Task</b></th>
<th>Start Date, Time</th>
<th>Estimated<br />Hours</th>
<?php
foreach( $dates as $date )
{
$date = DateTime::createFromFormat("Y-m-d", $date);
echo '<th>'. $date->format("m-d") .'</th>';
}
?>
<th>Progress</th>
</tr>
</thead>
<tbody>
<?php
foreach( $week_tasks as $task )
{
echo '<tr>
<td>'. $task->projectname .' | '. $task->structurename .' | <b>'. $task->taskname .'</b></td>
<td>'. $task->taskstartdate .'</td>
<td>'. $task->estimatedhours .'</td>
<td> '. $task->hours .' </td>
<td> '. $task->hours .' </td>
<td> '. $task->hours .' </td>
<td> '. $task->hours .' </td>
<td> '. $task->hours .' </td>
<td>
'. $progress .'
</td>
</tr>';
}
?>
</tbody>
</table>
提前致谢。
【问题讨论】:
-
测试一下,让我知道状态
foreach($arr as $val){ $a = get_object_vars($val); ?><tr><?php foreach($a as $v ){ echo '<td>$v</td>'; } ?> </tr> <?php } -
嗨。它给出了类似prnt.sc/afgfx5 的内容,感谢您的帮助:))
-
试试这是我的愚蠢
foreach($arr as $val){ $a = get_object_vars($val); ?><tr><?php foreach($a as $v ){ echo '<td>' . $v . '</td>'; } ?> </tr> <?php }。 -
它给了我这个prnt.sc/afgfx5,它与预期的有点不同。
-
现在这个
foreach($arr as $val){ $a = get_object_vars($val); ?><tr><?php foreach($a as $v ){ echo "<td>"; var_dump($v); echo "</td>" } ?> </tr> <?php }