我必须根据值匹配显示td值。下表中具有月日期。在$monthdays
中,我得到了月份天数,而在$listmonthdisplay
中,我得到了月份中的所有日期。
在$employeeDetail
数组中,我得到了月份日期。如果 attendence_date 等于$listmonthdisplay
,但是当$employeeDetail
数组中缺少任何日期时,我正在表中显示 attenence_date 循环失败或不继续。这里如何正确映射tb值?
$monthdays=28;
$listmonthdisplay=[
"0"=>"01-02-2019",
"1"=>"02-02-2019",
"2"=>"03-02-2019",
"3"=>"04-02-2019",
"4"=>"05-02-2019", ............"28"=>"05-02-2019"
]
$employeeDetail=[
"0"=>["attendence_date"=>"01-02-2019"],
"1"=>["attendence_date"=>"02-02-2019"],
"2"=>["attendence_date"=>"05-02-2019"],
"3"=>["attendence_date"=>"08-02-2019"],
"5"=>["attendence_date"=>"09-02-2019"]
]
<table>
<tr>
<?php for($i=0;$i<$monthdays;$i++){ ?>
<th><?php echo $listmonthdisplay[$i]?></th>
<?php }?>
</tr>
<tr>
<?php for($i=0;$i<$monthdays;$i++){ ?>
<td>
<?php
if((isset($employeeDetail[$i]) && $listmonthdisplay[$i]==$employeeDetail[$i]['attendence_date']){
echo $employeeDetail[$i]['attendence_date'];
}?>
</td>
<?php }?>
</tr>
</table>
Current output:
<table>
<tr>
<th>01-02-2019</th>
<th>02-02-2019</th>
<th>03-02-2019</th>
<th>04-02-2019</th>
<th>05-02-2019</th>
<th>06-02-2019</th>
<th>07-02-2019</th>
<th>08-02-2019</th>
<th>09-02-2019</th>........<th>28-02-2019</th>
</tr>
<tr>
<td>01-02-2019</td>
<td>02-02-2019</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>.......<td></td>
</tr>
</table>
Expected output:
<table>
<tr>
<th>01-02-2019</th>
<th>02-02-2019</th>
<th>03-02-2019</th>
<th>04-02-2019</th>
<th>05-02-2019</th>
<th>06-02-2019</th>
<th>07-02-2019</th>
<th>08-02-2019</th>
<th>09-02-2019</th>
</tr>
<tr>
<td>01-02-2019</td>
<td>02-02-2019</td>
<td></td>
<td></td>
<td>05-02-2019</td>
<td></td>
<td></td>
<td>08-02-2019</td>
<td>09-02-2019</td>.......<td></td>
</tr>
</table>
答案 0 :(得分:1)
我已对其进行编辑,并且现在可以正常使用。
<?php
$monthdays=28;
$listmonthdisplay=[
"0"=>"01-02-2019",
"1"=>"02-02-2019",
"2"=>"03-02-2019",
"3"=>"04-02-2019",
"4"=>"05-02-2019",
"5"=>"06-02-2019",
"6"=>"07-02-2019",
"7"=>"08-02-2019",
"8"=>"09-02-2019",
"9"=>"10-02-2019",
"10"=>"11-02-2019",
"11"=>"12-02-2019"
...
];
$employeeDetail=[
"0"=>["attendence_date"=>"01-02-2019"],
"1"=>["attendence_date"=>"02-02-2019"],
"2"=>["attendence_date"=>"05-02-2019"],
"3"=>["attendence_date"=>"08-02-2019"],
"5"=>["attendence_date"=>"09-02-2019"]
];
$tmpArray = array_column($employeeDetail, 'attendence_date');
?>
<table>
<tr>
<?php
for($i=0;$i<$monthdays;$i++){
echo "<th>".$listmonthdisplay[$i]."</th>";
}
?>
</tr>
<tr>
<?php
for($i=0;$i<$monthdays;$i++){
echo "<td>";
if(in_array($listmonthdisplay[$i], $tmpArray)){
echo $listmonthdisplay[$i];
}
echo "</td>";
}
?>
</tr>
</table>
我已经更改了两件事,并且现在可以正常使用
首先添加以下代码:
$tmpArray = array_column($employeeDetail, 'attendence_date');
获取要打印的一维日期数组
第二种是将条件更改为$ tmpArray