Is there something called empty coalescing operator like Null coalescing operator

PHP 7 adds the null coalesce operator:

// Fetches the value of $_GET['number'] and returns 'nonumber -NULL'
// if it does not exist.
$username = $_GET['number'] ?? 'No Number';
// This is equivalent to:
$username = isset($_GET['number']) ? $_GET['number'] : 'No Number';

Is there something for empty also?

Looking for something like,

/ Fetches the value of $_GET['number'] and returns '0' Empty
// if it does not empty.
$username = $_GET['number'] ?? 'no number or number is 0 or empty';

Upvotes: 5

Views: 1862

Answers (1)

Peter
Peter

Reputation: 31691

Yes, thanks to type coercion the short ternary operator ?:

Upvotes: 3

Related Questions