Dainius Vaičiulis Dainius Vaičiulis - 7 months ago 26
PHP Question

PHP - elegant way to check if assoc array value has a subarray?

Is there any elegant way to check if

$review['passenger']
has any
$review['passenger']['*']
?

Answer

Try with is_array(). It will check if it is an array or not -

if(is_array($review['passenger'])) {
   // is an array
}

Or if you want to check if some key is present or not then -

if(array_key_exists('key', $review['passenger'])) { ... }