Value coalescence in PHP
function coalesce() { $args = func_get_args(); foreach ($args as $arg) { if (!empty($arg)) { return $arg; } } return $args[0]; }
The function assumes that it will be called with at least one value. It can be trivially altered to use is_null() instead if that suits.