If else shortcut

The general format

(condition) ? (true return value) : (false return value)

Example

echo ‘Based on your score, you are a ‘,($score > 10 ? ‘genius’ : ‘nobody’);

References:

http://us2.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary

http://davidwalsh.name/php-shorthand-if-else-ternary-operators

Leave a Reply

Your email address will not be published. Required fields are marked *