Sorry if the title isn’t clear enough, but in Javascript you can do this :
var input = null;
var fruit = input || 'default';
Just wondering if PHP supports that kind of checking, currently I’m using :
$fruit = !empty($input)?$input : ‘default’ ;
Which is quite good, but of course the Javascript method is more elegant.
Thanks
||returns a boolean in PHP, so this operator cannot be used for it. Same foror.However, you can use the binary
?:operator if you are using PHP5.3+:However, it has one great disadvantage destroying its usefulness in the single case where it would be most useful (when importing request variables):
This would throw an
E_NOTICEin your face if$_REQUEST['fruit']didn’t exist. So in this case you still need the ternary version of it with anissetor!emptycheck.