Using the ternary operator in PHP

The ternary operator is an excellent and often underutilized way to quickly evaluate a variable in place of an if/else statement. The syntax is clean and can greatly simplify code.

( expr1 ) ? ( expr2 ) : ( expr3 )

Take the following code for example where we determine how to greet a user.

<?php
[...]