Ternary Operators  php 

using Ternary Operators in PHP


/* a bit tougher */
$score = 10;
$age = 20;
echo 'Taking into account your age and score, you are
: ',($age > 10 ? ($score < 80 ? 'behind' : 'above average') : ($score < 50 ? 'behind' : 'above average')); 
// returns 'You are behind'


/* "thankfully-you-don't-need-to-maintain-this" level */
 $days = ($month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year %400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31)); //returns days in the given month


 /* echo, inline */
echo 'Based on your score, you are a ',($score > 10 ? 'genius' : 'nobody'); //harsh!



/* shorthand usage */
$message = 'Hello '.($user->get('first_name') ?: 'Guest');


/* another basic usage */
$message = 'Hello '.($user->is_logged_in() ? $user->get('first_name') : 'Guest');