What is a more elegant solution to these nested if/elseif statements?

后端 未结 9 1888
野趣味
野趣味 2021-01-12 17:09

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

9条回答
  •  旧时难觅i
    2021-01-12 17:47

    Somewhat less readable, but effective):

    list($idx,$name) = array_shift(array_filter(array(
        $names['display_name'],
        implode(' ',array_filter(array($names['first_name'],$names['last_name']))),
        'user'.$names['id'];
        )));
    

提交回复
热议问题