-3

如何将代码附加到变量。

<?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";
?>
4

2 回答 2

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";
?>
于 2013-01-31T14:17:07.650 回答
-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";
?>

文档

于 2013-01-31T14:17:10.160 回答