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
public function nameify($names = NULL) {
if ($names) {
if (!empty($names['display_name'])) {
return $names['display_name'];
}
if (!empty($names['first_name'])) {
$name = $names['first_name'];
}
if (!empty($names['last_name'])) {
$name .= ' ' . $names['last_name'];
}
if (empty($name) && !empty($names['id'])) {
$name = 'user' . $names['id'];
}
}
return $name ? ltrim($name) : 'NULL';
}
Set the default first, and return that if nothing else matches. Then since we always want to return the display name if we have it do just that.
EDIT: Tweak to prevent returning "NULL "