PHP shorthand for isset()? [duplicate]

我的未来我决定 提交于 2019-11-27 11:25:08
hek2mgl

Update for PHP 7 (thanks shock_gone_wild)

PHP 7 introduces the so called null coalescing operator which simplifies the below statements to:

$var = $var ?? "default";

Before PHP 7

No, there is no special operator or special syntax for this. However, you could use the ternary operator:

$var = isset($var) ? $var : "default";

Or like this:

isset($var) ?: $var = 'default';

You can use new ternary operator (PHP 5.3+)

isset($var) ?: $var = "";

Or for older version :

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