PHP if shorthand and echo in one line - possible?

◇◆丶佛笑我妖孽 提交于 2019-12-01 02:16:19
Dave
<?=(expression) ? $foo : $bar?>

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

edit: more to read

echo expression ? $foo : $bar;

The ternary operator evaluates to the value of the second expression if the first one evaluates to TRUE, and evaluates to the third expression if the first evaluates to FALSE. To echo one value or the other, just pass the ternary expression to the echo statement.

echo expression ? $foo : $bar;

Read more about the ternary operator in the PHP manual for more details: http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!