Answer the question
In order to leave comments, you need to log in
How to output data from a multidimensional array to a table?
Compiler
<?php
$names = array ('Петров' => "Петр", 'Иванов' => "Иван", 'Сергеев' => "Сергей");
$FullArray = array (
'id' => array(1, 2, 3),
'name' => array ($names)
);
echo '<table>';
echo '<tr><th>ID</th><th>Имя</th><th>Фамилия</th></tr>';
foreach($FullArray as $key => $massive){
foreach ($massive as $inner_key => $value)
echo '<tr><td>'.$value.'</td><td>'.$value.'</td></tr>';
echo '</table>';
}
//print_r ($FullArray);
?>
Answer the question
In order to leave comments, you need to log in
First, learn how to create these same arrays. You are full of rubbish.
<?php
$arr = [
['firsname' => 'Иван', 'lastname' => 'Иванов'],
['firsname' => 'Петр', 'lastname' => 'Петров'],
['firsname' => 'Сергей', 'lastname' => 'Сергеев'],
]
?>
<table>
<tr><th>ID</th><th>Имя</th><th>Фамилия</th></tr>
<?php foreach($arr as $key => $person): ?>
<tr>
<td><?=$key?></td>
<td><?=$person['firsname']?></td>
<td><?=$person['lastname']?></td>
</tr>
<?php endforeach ?>
</table>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question