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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -