Is there in PHP something similar to JavaScript\'s:
alert(test || \'Hello\');
So, when test is undefined or null we\'ll see Hello, otherwis
One-liner. Super readable, works for regular variables, arrays and objects.
// standard variable string
$result = @$var_str ?: "default";
// missing array element
$result = @$var_arr["missing"] ?: "default";
// missing object member
$result = @$var_obj->missing ?: "default";
See it in action: Php Sandbox Demo