我需要我的 PHP 页面来显示以下结构:
<table border="1">
<tr>
<td>Title one</td><td>Title two</td>
</tr>
<tr>
<td>I'm content one</td><td>And here's content two</td>
</tr>
</table>
这是我的php页面:
$array = array( array( Title => "Title one"), array( Title => "Title two") );
$array2 = array( array( Content => "I'm content one"), array( Content => "And here's content two") );
$myvar ="Title one";
$htm .="<table border='1'>";
for ($i=0; $i<=1; $i++)
{
$htm .="<tr>";
foreach ($array[$i] as $title)
{
$htm .="<td >".$title."</td>";
foreach($array2 as $b)
{
$content = $b['Content'];
if ($myvar == $title)
{
$htm .="<tr><td>".$content."</td></tr>";
}else
{
$htm .="<tr><td ></td></tr>";
}
}
}
}
$htm .="</table>";
echo $htm;
正在输出:
<table border='1'>
<tr>
<td >Title one</td><tr><td>I'm content one</td>
</tr>
<tr>
<td>And here's content two</td></tr>
<tr><td >Title two</td><tr>
<td></td></tr><tr><td ></td></tr>
</table>
如何修改 html 输出以获得我需要的结构?