簡體   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