我最喜欢JavaScript的一点是它的逻辑运算符非常强大:
&&
can be used to safely extract the value of an object's field, and will return null if either the object or the field has not been initialized// returns null if param, param.object or param.object.field // have not been set field = param && param.object && param.object.field;
||
can be used to set default values:// set param to its default value param = param || defaultValue;
PHP是否也允许使用逻辑运算符进行这种操作?