I have this kind of test again, and again, and I feel like there is a more elegant way to do it.
(isset($country['capital'])) ? $country['capital'] : null
Can you help me?
I have this kind of test again, and again, and I feel like there is a more elegant way to do it.
(isset($country['capital'])) ? $country['capital'] : null
Can you help me?
You can use or
Operator In Laravel Blade template
$country['capital'] or null
And In php 7 you can use Null coalescing operator
$country['capital'] ?? null
The null coalescing operator (??) has been added as syntactic sugar for the common case of needing to use a ternary in conjunction with isset(). It returns its first operand if it exists and is not NULL; otherwise it returns its second operand.