I have an array in below format
(
[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
)
)
I want to get output from that array as below format
Can anyone please help me regarding this problem. thanks
try this.
<?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>";
}
}
?>
Firstly you need to show some effort, you can't expect people to write code for you. You need to try something, that's how you learn. Copy and pasting code won't help you.
<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>
<?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>";
}
}
?>