Heredoc语法的替换

问题描述 投票:1回答:1
    foreach($array["$new"]['features'] as $key => $feature) :
      $features .= <<< ____EOT
        <li> $feature </li>
____EOT;
    endforeach;

当前,我正在使用heredoc语法,但这有其缺点。还有其他PHP方法可以使用Heredoc语法完成相同的操作吗?

php loops foreach heredoc
1个回答
2
投票

只需使用字符串。

$features .= "<li> $feature </li>";

Heredoc的优点是您不必担心在值中转义引号,因此对于较长的HTML块非常有用。

© www.soinside.com 2019 - 2024. All rights reserved.