Based on the examples from this page, I have the working and non-working code samples below.
Working code using if
statement:
if (!empty($address['street2'])) echo $address['street2'].'<br />';
Non-working code using ternary operator:
$test = (empty($address['street2'])) ? 'Yes <br />' : 'No <br />';
// Also tested this
(empty($address['street2'])) ? 'Yes <br />' : 'No <br />';
UPDATE
After Brian's tip, I found that echoing $test
outputs the expected result. The following works like a charm!
echo (empty($storeData['street2'])) ? 'Yes <br />' : 'No <br />';