Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There must be a better way (php, string)

I want to display a user's firstname if they gave us one, otherwise their email. The code below functions, but I don't like how it takes so many lines, I vaguely recall some way of maybe doing this with OR? I have (essentially):

if ($firstname == "")
{
$name   = $email;
}else{
$name = $firstname;
}
echo $name;
like image 353
mazlix Avatar asked Mar 06 '26 09:03

mazlix


1 Answers

echo ($firstname) ? $firstname : $email;
like image 166
Alex Pliutau Avatar answered Mar 07 '26 22:03

Alex Pliutau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!