I'm working with ACF in WP which provides a get_field()
function. The function can return an array of values, null
or false. When the result of the function doesn't contain an array of values I want to default to an empty array.
This is how I do it at the moment but would like to know if there's a neater way to accomplish the same thing.
// can these lines be combined into one without multiple function calls?
$field = get_field('mobile_menu', 'option');
$field = $field ? $field : [];
return collect($field); // other processing
[php] elvis
\$\endgroup\$