I have following code in php:
$mode = $this->input->get('mode'); // may return string or boolean false
if(!$mode)
$mode = 'default';
how can shorten this code to one line with fastest execution
Is this perfect one:
$mode = ($mode=$this->input->get('mode'))?$mode:'default';
But why bother for something this small?
Please note that the actual result of evaluating the above expression is
truebut that expression is not assigned to anything. If we were to do$something = ($mode = $this->input->get('mode') or $mode = "default");we would gettruein$something. To make it clearer what I wrote above is evaluated like this: