I
I
Ibishka2020-05-12 13:29:56
PHP
Ibishka, 2020-05-12 13:29:56

Why $inputs = 0?

$inputs = '';
$inputs .= '<input type="hidden" name="item_name_' . $index ? $index : 1 . '>" value="' . $item['title'] . '">
              <input type="hidden" name="quantity_' . $index ? $index : 1 . '" value="' . $count . '">
              <input type="hidden" name="amount_' . $index ? $index : 1 . '" value="' . $total . '">';

Yes, the problem is in checking $index how to write a condition so that it does not equal 0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-05-12
@Ibishka

The concatenation is performed before the ternary operator. As a result, your line looks like

$inputs .= ('<input type="hidden" name="item_name_' . $index)
  ? $index 
  : (1 . '>" value="' . $item['title'] . '"><input type="hidden" name="quantity_' . $index)
    ? $index
    : (1 . '" value="' . $count . '"><input type="hidden" name="amount_' . $index)
      ? $index
      : (1 . '" value="' . $total . '">');

Specify the order of operations explicitly with parentheses.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question