PHP variable "default value"
You can define it in one script and then require_once
that script in your other scripts
You could also just use the ternary operator:
$myVar = isset($var)?$var:$default;
From PHP 7, you can now use the null coalescing operator :
$var ?? $default
that does exactly like your function
Use this concise alternative:
isset($myVar) || $myvar=$default;
The ||
operator is short circuit, it will not evaluate second operant if the first one be evaluated true.