如何在PHP字符串元素中编写PHP if语句? $element=”
$Name $Title ";如何在PHP字符串元素中编写PHP if语句? $element=”,php,html,Php,Html,$Name $Title "; 此变量$element包含HTML代码,我想在其中运行此if语句,但不拆分该变量,因为我想在其他地方回显整个变量。您不能按要求执行,但可以执行具有相同效果的操作: $element = " <div class='product-info'> <p>$Name</p> <?php if () {}?> <
此变量$element包含HTML代码,我想在其中运行此if语句,但不拆分该变量,因为我想在其他地方回显整个变量。您不能按要求执行,但可以执行具有相同效果的操作:
$element = " <div class='product-info'>
<p>$Name</p>
<?php if () {}?>
<p>$Title</p>
</div>";
$element=“$Name”;
如果(某些条件){
$element.=“一些文本”;
}否则{
$element.=“其他一些文本”;
}
$element.=“$Title”;
不要将if语句放在字符串中。在if语句中插入字符串。我想在其他地方回显整个变量好的,你可以通过拆分变量来实现。好的,我在if语句中插入了字符串,谢谢。换句话说,“在if语句中插入字符串”
$element = " <div class='product-info'><p>$Name</p>";
if (some condition) {
$element .= "some text";
} Else {
$element .= "Some other text";
}
$element .= "<p>$Title</p> </div>";