如何将代码附加到变量。
<?php
echo "<ul>\n";
foreach($related as $r) {
if ($r->Count > 0) {
echo "<li>" . "<a>". $r->post_title ."</a>". "\n";
f_tree_av($r->post_id, $level + 1);
echo "</li>";
} elseif ($r->Count==0) {
echo "<li>" . "<a>". $r->post_title ."</a>". "\n";
} else;
}
echo "</ul>\n";
?>
答案 0 :(得分:1)
<?php
$content .= "<ul>\n";
foreach($related as $r) {
if ($r->Count > 0) {
$content .= "<li>" . "<a>". $r->post_title ."</a>". "\n";
f_tree_av($r->post_id, $level + 1);
echo "</li>";
} elseif ($r->Count==0) {
$content .= "<li>" . "<a>". $r->post_title ."</a>". "\n";
} else;
}
$content .= "</ul>\n";
?>
答案 1 :(得分:-1)
只需使用.=
运算符,即$a = $a . "...";
($a .= "..."
)
<?php
$content = "<ul>\n";
foreach($related as $r) {
if ($r->Count > 0) {
$content .= "<li>" . "<a>". $r->post_title ."</a>". "\n";
f_tree_av($r->post_id, $level + 1);
$content .= "</li>";
} elseif ($r->Count==0) {
$content .= "<li>" . "<a>". $r->post_title ."</a>". "\n";
} else;
}
echo $content . "</ul>\n";
?>