2012.06.20

Conditional statement mid echo


Astonishingly I've only just discovered this. In PHP there is a way to put a conditional statement in the middle of an echo statement using the ternary operators. I've been using ternary for a long time but it never occurred to me that I could I use it like this:

    $temp = 3;
    echo '<p>The weather today is '. ($temp > 18 ? 'hot' : 'cold') .'.</p>';

programming

Burst forth on 20th June 2012 at 11:18 and vaguely filed under programming.

Witty rejoinders


Nothing yet!

(never published)
http://
Captcha: