繁体   English   中英

如何在 PHP 中将一个条件包装在另一个条件中

[英]How to Wrap A Condition Inside Another Condition in PHP

任何人都可以帮助我将条件包装在 php 中的另一个条件中。

我有这个代码 #1,我想在代码 #2 中。

这是代码#1

<?php if( get_field('highlights') ): ?>
    <div class="overview">
    <h3>Quick Overview</h3>
    <?php the_field('highlights'); ?>
    </div>
<?php endif; ?>

这是代码#2

<?php if(strstr($_SERVER['HTTP_REFERER'],'www.example.com')) 
{
  echo '**CODE #1 should be placed here**';
}
?>

抱歉,我对 PHP 没有任何了解。

将代码 1 包装在代码 2 中

经过多次试验和错误,这就是我必须让它发挥作用的方法。 如果有什么不对或需要改进的地方,请纠正我。

<?php if (strstr($_SERVER['HTTP_REFERER'], 'www.google.com')){ ?>
      
    <?php if( get_field('highlights') ):?>
      <div class="overview">
      <h3>Quick Overview</h3>
      <?php the_field('highlights'); ?>
    </div>
<?php endif; ?>
<?php } ?>

这在理论上应该有效。 虽然我不确定highlights字段的用途。

<?php 
if(strstr($_SERVER['HTTP_REFERER'],'www.example.com')){
  if( get_field('highlights') ){ ?>
    <div class="overview">
    <h3>Quick Overview</h3>
    <?php the_field('highlights'); ?>
    </div>
    <?php 
  }
}
?>

您可能想要替换<?php the_field('highlights'); ?> <?php the_field('highlights'); ?>使用类似<?=highlight?>的内容,并在循环中遍历突出显示。 不过这要视情况而定。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM