Miscellany
public text v1 · immutable/**
* Return a variable if it exists or $or if it doesn't. Optionally require
* variable to match specific syntax.
*
* @param $var The variable to use.
* @param $or The fallback.
* @param $regex Optional, the regular expression to require of the var.
* @return The variable's value.
*/
function ifsetor(&$var, $or, $regex = false) {
if (empty($var) || ($regex && !preg_match($regex, $var))) {
$var = $or;
}
return $var;
}