PHP shorthand for isset()? -
this question has answer here:
is there shorthand way assign variable if doesn't exist in php?
if(!isset($var) { $var = ""; }
i'd like
$var = $var | "";
update php 7 (thanks shock_gone_wild)
php 7 introduces called null coalescing operator simplifies below statements to:
$var = $var ?? "default";
before php 7
no, there no special operator or special syntax this. however, use ternary operator:
$var = isset($var) ? $var : "default";
or this:
isset($var) ?: $var = 'default';
Comments
Post a Comment