I've to display the td value as per th value matching. Here in the below table has th which has month dates. In the $monthdays
I'm getting month days count and in the $listmonthdisplay
I'm getting all the dates of the months.
In the $employeeDetail
array I'm getting the month dates. In the table I'm doing foreach to display attendence_date if attendence_date is equal to $listmonthdisplay
but when any dates is missing in the $employeeDetail
array then loop is failing or not going forward. Here How can correctly I map the tb value?
$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>