I have an array like this:
Array (
[0] => "name" => "John","id" => "1"
[1] => "name" => "Mary","id" => "2"
[2] => "name" => "Sean","id" => "3"
)
How can I make a table like this:
1 | John
2 | Mary
3 | Sean
Thank you!
I have an array like this:
Array (
[0] => "name" => "John","id" => "1"
[1] => "name" => "Mary","id" => "2"
[2] => "name" => "Sean","id" => "3"
)
How can I make a table like this:
1 | John
2 | Mary
3 | Sean
Thank you!
Loop through the array and output all values as you want it formatted.
foreach($arr as $item){
echo "$arr[id] | $arr[name]";
}
Or if its a HTML table you want
<table>
<?php foreach($arr as $item): ?>
<tr>
<td><?= $arr['id'] ?> </td><td> <?= $arr['name']; ?></td>
</tr>
<?php endforeach; ?>
</table>
Asuming that the name of your arreglo is $users
, you can loop through each element and output the data of that element in a row of the table:
<table>
<thead>
<th>ID</th>
<th>Name</th>
<thead>
<tbody>
<?php
foreach ($users as $user) {
echo '<tr>';
echo '<td>'.$user['id'].'</td>';
echo '<td>'.$user['name'].'</td>';
echo '</tr>';
}
?>
</tbody>
</table>