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
Witty rejoinders
| (never published) | |
| http:// | |
| Captcha: | |