检查里程[关闭]

I need to check the number of miles of products. And if it is 1 it need to be

mile

, if is more than 1 it need to be

miles

Can anybody help me?

<span class="text-red">
    if(<?= $this->product->getMiles() ?> == 1) {
        <span><?= $this->product->getMiles() ?> mile</span>
    } else {
        <span><?= $this->product->getMiles() ?> miles</span>
    }
</span>

PHP code should be wrapped inside the <?php ?> tags. It should be -

<span class="text-red">
    <?php if($this->product->getMiles() == 1) { ?>
        <span><?php echo $this->product->getMiles() ?> mile</span>
    <?php } else { ?>
        <span><?php echo $this->product->getMiles() ?> miles</span>
    <?php } ?>
</span>

You can use a ternary operator:

<span class="text-red">
  <span><?= ($this->product->getMiles() == 1) ? $this->product->getMiles()." mile" : $this->product->getMiles()." miles"; ?></span>
</span>