I have following array of record which contains user as well as location information:
$arr =
[
[
'user_id' => 5,
'l_id' => 10,
'Name' => 'John Doe',
'Location' => 'Chicago',
'date' => '2021-10-02'
],
[
'user_id' => 5,
'l_id' => 11,
'Name' => 'John Doe',
'Location' => 'Houston',
'date' => '2021-10-02'
],
[
'user_id' => 6,
'l_id' => 12,
'Name' => 'Rob Doe',
'Location' => 'Dallas',
'date' => '2021-10-02'
],
[
'user_id' => 6,
'l_id' => 13,
'Name' => 'Rob Doe',
'Location' => 'Philadelphia',
'date' => '2021-10-02'
],
];
I'm trying to display same user/day location record in one td by using following code:
$html = '';
foreach ($arr as $ar) {
if ($ar['date'] == $ar['date']) {
$html .= '<tr>
<td>' . $ar['Name'] . '</td>
<td>' . $ar['date'] . '</td>
<td>' . $ar['Location'] . '</td>
</tr>';
}
}
HTML:
<table>
<thead>
<tr>
<th>Name</th>
<th>Date</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<?= $html; ?>
</tbody>
</table>
But it's repeating same date record multiple times (Name, Date):
Name Date Location
John Doe 2021-10-02 Chicago
John Doe 2021-10-02 Houston
Rob Doe 2021-10-02 Dallas
Rob Doe 2021-10-02 Philadelphia
And I want result like this:
Name Date Location
John Doe 2021-10-02 Chicago
Houston
--------------------------------------------
Rob Doe 2021-10-02 Dallas
Philadelphia