one feature of perl I'm desparately missing in php is using || to assign
the first non-empty value in a list to a variable. For example,
# perl example 1
$a = 1;
$b = 2;
$c = $a || $b;
print $c; # displays 1
# perl example 2
$a = 1;
$b = 2;
$c = $d || $b;
print $c; # displays 2, since $d is empty
# perl example 3
$a = 'apple';
$b = 'banana';
$c = 'cherry';
$d = $a || $b || $c;
print $d; # displays 'apple';
# perl example 4
$a = '';
$b = '';
$c = 'cherry';
$d = $a || $b || $c;
print $d; # displays 'cherry';
This is such a handy language construct. Is there any such php
equivalent that accomplishes this? I've already written a function to do
it. (Like this: $d = value($a, $b, $c). But making value() visible
everywhere is something I'd rather avoid if there's something built-in
to php.)
--cd