Reputation: 12445
In an online tutorial I have seen the following snippet of code:
$this->data = $data ?: \Input::all();
Is this a standard ternary operator? What would happen when $data
evaluates to true
?
Does the following code do the same thing as the original I posted?
$this->data = $data ? null : \Input::all();
Upvotes: 3
Views: 186
Reputation: 16458
It's a ternary operator, shortcut of
$this->data = $data? $data : \Input::all();
From http://php.net/manual/en/language.operators.comparison.php
Since PHP 5.3, it is possible to leave out the middle part of the ternary operator.
Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise.
Upvotes: 8