如何仅从 WHILE 循环中获取最后一个值


How do I get the last value only from WHILE loop?

我只想打印最后一个值,但它正在打印所有值:

<?php if (get_field('share_sentiment')):?>
<?php while (has_sub_field('share_sentiment')):?>
  <?php if (get_sub_field('share_medium')):?>
    <?php $kid = 0; ?>
    <?php while (has_sub_field('share_medium')):?>
      <?php
        $negative += get_sub_field('medium_negative');
        $positive += get_sub_field('medium_positive');
        $totalMinus = ($positive - $negative) / ($positive + $negative);
        $rounded = round($totalMinus, 3);
        print_r($rounded);
        ?>
        <?php endwhile;?>
     <?php endif;?>
<?php endwhile;?>
<?php endif;?>

print_r($rounded);放在循环之后。我猜也是$rounded = round($totalMinus, 3);

尝试使用 回声$variable;而不是print_r,因为使用的语言是 PHP?