I\'m building a website that contains users with user profiles. Many of the fields in the profile are optional.
There is an opportunity for a lot of user-generate
Using ternary conditions we can shorten and beautify the code:
public function nameify($names = NULL) {
$name = 'NULL';
if (!empty($names)) {
$name = ($names['display_name']) ? $names['display_name'] : trim($names['first_name']." ".$names['last_name']);
if(!$name) $name = ($names['id'] > 0) ? 'user'.$names['id'] : 'NULL';
}
return $name;
}