PHP如果发出其他问题

mtu*_*tle -1 php if-statement

我确信这很简单,但如果不打破我的页面,我就无法得到这个:

<?php
   $values = get_field('testimonial_text');
      if($values) {
      echo '                
      <div class="testimonial entry-content">
      <h2><?php the_field('testimonial_title'); ?></h2>
      <?php the_field('testimonial_text'); ?>
      </div>';
  } else {
       echo '';
      }
   ?>
Run Code Online (Sandbox Code Playgroud)

有人能告诉我我做错了什么,为什么我做的不行.

Nie*_*sol 8

你有嵌套<?php .. ?>块.这表明出现了问题!

<?php
  $values = get_field('testimonial_text');
  if($values) {
    echo '<div class="testimonial entry-content">';
    echo '<h2>'; the_field('testimonial_title'); echo '</h2>';
    the_field('testimonial_text');
    echo '</div>';
  }
  // your else was a no-op, so I removed it
?>
Run Code Online (Sandbox Code Playgroud)

  • @Jasper除了说嵌套块包含单引号,它从字符串中退出. (2认同)