Best way to give a variable a default value (simulate Perl ||, ||= )
I love doing this sort of thing in Perl: $foo = $bar || $baz to assign $baz to $foo if $bar is empty or undefined. You also have $foo ||= $bletch which will only assign $bletch to $foo if $foo is not defined or empty. The ternary operator in this situation is tedious and tiresome. Surely there's a simple, elegant method available in PHP? Or is the only answer a custom function that uses isset()?
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.