The Elvis Operator (?:) in PHP
The ?: operator, also known as the "Elvis operator," evaluates the left operand if it's truthy and the right operand otherwise. In short, it's a shortcut for the following:
foo = bar ? bar : baz;
Consider the code:
$items = $items ?: $this->_handle->result('next', $this->_result, $this);
This code evaluates to $items if it's truthy (not empty or false), and evaluates to the $this->_handle->result('next', $this->_result, $this) expression otherwise.
Key Points:
The above is the detailed content of What Does PHP's Elvis Operator (?:) Do and How Does It Work?. For more information, please follow other related articles on the PHP Chinese website!