There is a new operator in php 5.3 which does this: ?:
// A
echo 'A' ?: 'B';
// B
echo '' ?: 'B';
// B
echo false ?: 'B';
// B
echo null ?: 'B';
More Related Contents:
- PHP ternary operator vs null coalescing operator
- Speed difference in using inline strings vs concatenation in php5?
- PHP Elvis operator vs null coalescing operator
- Is micro-optimization worth the time?
- Speed difference in using inline strings vs concatenation in php5?
- Fastest way to convert string to integer in PHP
- PHP Objects vs Arrays — Performance comparison while iterating
- Why is Magento so slow? [closed]
- SELECT COUNT() vs mysql_num_rows();
- C#’s null coalescing operator (??) in PHP
- Difference between mt_rand() and rand()
- PHP short-ternary (“Elvis”) operator vs null coalescing operator
- PDO::rowCount VS COUNT(*)
- Algorithm to get the excel-like column name of a number
- Optimizing Kohana-based Websites for Speed and Scalability
- Which is faster? Constants, Variables or Variable Arrays
- how to get client’s IP address in sql database [closed]
- Working with large numbers in PHP
- Suppress error with @ operator in PHP
- Nginx location configuration (subfolders)
- Facebook Graph API, how to get users email?
- How to group a multidimensional array by a particular subarray value?
- How to write specific CSS for mozilla, chrome and IE
- How to put php inside JavaScript?
- Check if string contains a value in array [duplicate]
- Symfony2 AJAX Login
- can I get the unicode value of a character or vise versa with php?
- Bind Param with array of parameters
- regular expression and forward slash
- Convert delimited string into array key path and assign value