0

I have recently had to recode an echo statement on to two lines to get it to execute correctly. I was wondering if any one knew why. Original code:

<?php
echo $quantityDiscount['show_qty'] . '<br />' .  (is_numeric($quantityDiscount['discounted_price'])) ? $currencies->display_price($quantityDiscount['discounted_price'], zen_get_tax_rate($products_tax_class_id)) : $quantityDiscount['discounted_price']; ?>

New code:

<?php 
echo $quantityDiscount['show_qty'] . '<br />';
echo  (is_numeric($quantityDiscount['discounted_price'])) ? $currencies->display_price($quantityDiscount['discounted_price'], zen_get_tax_rate($products_tax_class_id)) : $quantityDiscount['discounted_price']; ?>

The original code output "£22.50"

The new code output correctly "3-5<br />£22.50"

Am I missing something or is this a feature of php 7.

Marcusbee
  • 11
  • 1
  • In the first version `$q . '
    ' . is_numeric(...)` is the condition. PHP doesn't know whether you mean `($q . '' . is()) ? :` or `$q . '' . (is() ? :)`.
    – deceze Jan 19 '18 at 16:32
  • @deceze is correct. Wrap the ENTIRE second conditional part, in `( ... )` to make it stick. (*Which I always do out of habit anyhow, so I never noticed this issue come up.*) – IncredibleHat Jan 19 '18 at 16:32

0 Answers0