Filling array data of php into html table

0 Saptorshi Dana · July 4, 2014
Is there a way to create table and then display values of array made in php into that table??

Post a Reply

Replies

Oldest  Newest  Rating
0 Alan Johnson · July 12, 2014
Yes, example:


<?php
$users = array(
'John' => 'Doe',
'Jane' => 'Doe',
'Joe' => 'Bloggs',
);
?>

<table>
<tr>
<th>First name</th>
<th>Last name</th>
</tr>
<?php foreach($users as $first_name => $last_name): ?>
<tr>
<td><?php echo $first_name ?></td>
<td><?php echo $last_name ?></td>
</tr>
<?php endforeach; ?>
</table>

0 Pere Garau Burguera · July 4, 2014
I guess you have to echo echo table tags and then loop through the array and echo a tr with the value each time you loop. 
  • 1

PHP

103,768 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators