?: operator (the 'Elvis operator') in PHP
问题 I saw this today in some PHP code: $items = $items ?: $this->_handle->result(\'next\', $this->_result, $this); I\'m not familiar with the ?: operator being used here. It looks like a ternary operator, but the expression to evaluate to if the predicate is true has been omitted. What does it mean? 回答1: It evaluates to the left operand if the left operand is truthy, and the right operand otherwise. In pseudocode, foo = bar ?: baz; roughly resolves to foo = bar ? bar : baz; or if (bar) { foo =