如何用三個標題這是將它變成表格的形式:公司名稱(ABC和XYZ),科(古晉和詩巫兩家公司分別),並根據兩家公司的工作人員的名字(到陣列)。我是初學者。請幫助,因爲我卡住了。我的代碼有問題。PHP foreach循環與數組表
<html>
<style>
</style>
<body>
<?php
$v_company= array(
'ABC'=>array('Kuching'=>array('Michael', 'Jenny'),
'Sibu'=>array('Sally', 'Muhammad', 'Mutu')
),
'XYZ'=>array('Kuching'=>array('Lucy', 'Abdullah'),
'Sibu'=>array('John', 'Alicia')
)
);
?>
<table>
<tr><th>Company's Name</th>
<th>Branch</th>
<th>Staff's Name</th>
</tr>
<?php
foreach($v_company as $v_company_name=>$v_company_info){
echo "<tr>";
echo "<td>";
echo "$v_company_name <br>";
echo "</td>";
echo "</tr>";
foreach($v_company_info as $v_branch=>$v_staffs){
echo "<td>";
echo "$v_branch <br/>";
echo "</td>";
foreach($v_staffs as $v_staff){
echo "<td>";
echo "$v_staff <br/>";
echo "</td>";
echo "Company: ". $v_company_name. ",Branch: ". $v_branch. ",Staff: " .$v_staff . "<br>";
}
}
}
?>
</table>
</body>
</html>
試試這個替代你更深入的foreach'的foreach($ v_staffs爲$ v_staff){回聲「」。爆( 「
」,$ v_staff)。 「」; }' – Bobot