Checking if array is multidimensional or not?

后端 未结 25 3559
醉话见心
醉话见心 2020-11-28 01:41
  1. What is the most efficient way to check if an array is a flat array of primitive values or if it is a multidimensional array?
25条回答
  •  悲&欢浪女
    2020-11-28 02:31

    I think this is the most straight forward way and it's state-of-the-art:

    function is_multidimensional(array $array) {
        return count($array) !== count($array, COUNT_RECURSIVE);
    }
    

提交回复
热议问题