Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP if shorthand and echo in one line - possible? [duplicate]

What's the best, preferred way of writing if shorthand one-liner such as:

expression ? $foo : $bar

Plot twist: I need to echo $foo or echo $bar. Any crazy tricks? :)

like image 958
Wordpressor Avatar asked Sep 10 '25 15:09

Wordpressor


2 Answers

<?=(expression) ? $foo : $bar?>

edit: here's a good read for you on the topic

edit: more to read

like image 85
Dave Avatar answered Sep 12 '25 10:09

Dave


echo (expression) ? $foo : $bar;
like image 26
A.M.N.Bandara Avatar answered Sep 12 '25 08:09

A.M.N.Bandara