What is the best way to determine if an array is multidimensional in PHP?

To determine if an array is multidimensional in PHP, you can check if any of its elements are also arrays. This can be done by iterating over the array and checking the data type of each element. If any element is an array, then the original array is multidimensional.

function is_multidimensional_array($array) {
    foreach ($array as $element) {
        if (is_array($element)) {
            return true;
        }
    }
    return false;
}

// Example usage
$array = [1, 2, [3, 4], 5];
if (is_multidimensional_array($array)) {
    echo 'The array is multidimensional.';
} else {
    echo 'The array is not multidimensional.';
}