【发布时间】:2017-10-05 05:13:17
【问题描述】:
如何将第一个 foreach 语句的输出放在表的一列中,而将另一个 foreach 语句的输出放在另一列中。我尝试了一些东西,但出于某种原因,它把它全部放在了一个列中。这是我的代码:
<table border="0" align="center">
<?php
foreach($anchors as $a) {
$text = $a->nodeValue;
$href = $a->getAttribute('href');
$i++;
if ($i > 16) {
if (strpos($text, "by owner") === false) {
if (strpos($text, "map") === false) {
echo "<tr><td><a href =' ".$href." '>".$text."</a><br/></td></tr>";
}
}
}
foreach($span as $s) {
echo "<tr><td>".$s->nodeValue."</td></tr>";
}
}
?>
</table>
【问题讨论】:
-
定义“列”。也请正确缩进你的代码。
-
我编辑了你的格式,但把右括号留给第一个被注释掉的
if语句——在你的代码中被注释掉了吗?无法判断第二个foreach是否应该在第一个foreach内。 -
我在您的代码中没有看到任何表格。你想只用 CSS 做这个吗?
-
我在您的代码中看不到任何 CSS。 (请删除 CSS 标签)
-
你们去吧,添加表格。
标签: php html foreach html-table