Php 将if与我的foreach结构一起使用

Php 将if与我的foreach结构一起使用,php,if-statement,foreach,Php,If Statement,Foreach,我的foreach使用以下结构我将如何使用相同格式的if语句 <?php foreach($property as $section):?> if(!empty($section)) { echo <p>data here </p>; }else{ html } <?php endforeach;?> 如果(!空($section)) { 回声这里的数据; }否则{ html } 不

我的foreach使用以下结构我将如何使用相同格式的if语句

<?php foreach($property as $section):?>


    if(!empty($section))
    {
      echo <p>data here </p>;
    }else{
      html
    }

<?php endforeach;?>

如果(!空($section))
{
回声这里的数据

; }否则{ html }
不确定您的意思,但您没有有效的php

foreach($property as $section) {
    if(!empty($section))
    {
      echo '<p>data here </p>';
    }else{
      echo 'html';
    }
}
foreach($property作为$section){
如果(!空($section))
{
在此处回显“数据”

; }否则{ 回音“html”; } }
不确定您的意思,但您没有有效的php

foreach($property as $section) {
    if(!empty($section))
    {
      echo '<p>data here </p>';
    }else{
      echo 'html';
    }
}
foreach($property作为$section){
如果(!空($section))
{
在此处回显“数据”

; }否则{ 回音“html”; } }


请参阅:




请看:

我想您正在寻找这个

<?php foreach($property as $section): ?>
    <?php
        if(!empty($section)) :
            echo <p>data here </p>;
        else :
            html
        endif;
endforeach; ?>

我想你在找这个

<?php foreach($property as $section): ?>
    <?php
        if(!empty($section)) :
            echo <p>data here </p>;
        else :
            html
        endif;
endforeach; ?>

速记:

<?php foreach($property as $section):?>
    <?php if(!empty($section)):?>
      <p>data here </p>;
    <?php else: ?>
      html
    <?php endif;?>
<?php endforeach;?>

这里的数据

; html
其他:

<?php foreach($property as $section)
 {
   if(!empty($section))
   {
     echo '<p>data here </p>';
   }else{
       echo 'html';
   }
 }
?>

速记:

<?php foreach($property as $section):?>
    <?php if(!empty($section)):?>
      <p>data here </p>;
    <?php else: ?>
      html
    <?php endif;?>
<?php endforeach;?>

这里的数据

; html
其他:

<?php foreach($property as $section)
 {
   if(!empty($section))
   {
     echo '<p>data here </p>';
   }else{
       echo 'html';
   }
 }
?>

这是一个包含
}elseif{
的示例:

<?php foreach($property as $section):?>

<?php    if(!empty($section)): ?>

      <p>data here </p>

<?php   elseif ([another condition]): ?>

      ...

<?php   else: ?>

      html

<?php   endif: ?>

<?php endforeach;?>

这里的数据

... html

整个文档都在这里:

这是一个包含
}elseif{
的示例,另外:

<?php foreach($property as $section):?>

<?php    if(!empty($section)): ?>

      <p>data here </p>

<?php   elseif ([another condition]): ?>

      ...

<?php   else: ?>

      html

<?php   endif: ?>

<?php endforeach;?>

这里的数据

... html

整个文档都在这里:

我认为最好的解决方案是:

<?php
foreach($property as $section) {
    if(!empty($section))
    {
        echo '<p>data here </p>';
    }
    else
    {
        ?>
        <div id="dosome">really crazy html stuff here</div>
        <?php
    }
}
?>

这里的html真是太疯狂了

我认为最好的解决方案是:

<?php
foreach($property as $section) {
    if(!empty($section))
    {
        echo '<p>data here </p>';
    }
    else
    {
        ?>
        <div id="dosome">really crazy html stuff here</div>
        <?php
    }
}
?>

这里的html真是太疯狂了

“在同一格式内”-这意味着什么?@SergioTulentsev使用endforeach和:“在同一格式内”-这意味着什么?@SergioTulentsev使用endforeach和:固定打开/关闭标记和回显引号固定打开/关闭标记和回显引号