我有一个以下格式的数组
(
[Albania] => Array
(
[0] => stdClass Object
(
[name] => Margaret Ramirez
[date_of_birthday] => 24-Mar-1997
[email] => mramirez1g@godaddy.com
[department] => Engineering
)
)
[Argentina] => Array
(
[0] => stdClass Object
(
[name] => Samuel Fisher
[date_of_birthday] => 16-Jan-1955
[email] => sfisher1e@amazon.co.uk
[department] => Sales
)
)
[Azerbaijan] => Array
(
[0] => stdClass Object
(
[name] => Jason Mccoy
[date_of_birthday] => 11-Nov-2001
[email] => jmccoy22@shop-pro.jp
[department] => Research and Development
)
)
任何人都可以帮我解决这个问题。 感谢
答案 0 :(得分:1)
首先你需要付出一些努力,你不能指望人们为你编写代码。你需要尝试一些东西,这就是你学习的方式。复制和粘贴代码对您没有帮助。
<table>
<tr>
<th>Name</th>
<th>Date of Birth</th>
<th>Email</th>
<th>Department</th>
</tr>
<?php
foreach ($countries as $country) : ?>
<tr>
<td><?php echo $country['name']; ?></td>
<td><?php echo $country['date_of_birthday']; ?></td>
<td><?php echo $country['email']; ?></td>
<td><?php echo $country['department']; ?></td>
</tr>
<?php endforeach; ?>
</table>
答案 1 :(得分:0)
试试这个。
<?php
foreach ($country as $key => $value) {
foreach ($value as $index => $val) {
echo "<tr>";
echo "<td>".$val['name']."</td>";
echo "<td>".$val['date_of_birthday']."</td>";
echo "<td>".$val['email']."</td>";
echo "<td>".$val['department']."</td>";
echo "</tr>";
}
}
?>
答案 2 :(得分:0)
<?php
foreach($country as $contryKey => $contryValue) {
foreach($contryValue as $index => $objValue) {
echo "<tr>";
echo "<td>".$objValue->name."</td>";
echo "<td>".$objValue->date_of_birthday."</td>";
echo "<td>".$objValue->email."</td>";
echo "<td>".$objValue->department."</td>";
echo "</tr>";
}
}
?>