在PHP中是否有类似C#中的??
的三元运算符或类似的操作符?
??
在C#中很简洁,但在PHP中你需要做像下面这样的事情:
// This is absolutely okay except that $_REQUEST['test'] is kind of redundant.
echo isset($_REQUEST['test'])? $_REQUEST['test'] : 'hi';
// This is perfect! Shorter and cleaner, but only in this situation.
echo null? : 'replacement if empty';
// This line gives error when $_REQUEST['test'] is NOT set.
echo $_REQUEST['test']?: 'hi';
echo @$_REQUEST ['someres'] ?: 'hi';
,其中抑制了错误。 - El Yobo