Checking if array is multidimensional or not?

后端 未结 25 3554
醉话见心
醉话见心 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:43

    Try as follows

    if (count($arrayList) != count($arrayList, COUNT_RECURSIVE)) 
    {
      echo 'arrayList is multidimensional';
    
    }else{
    
      echo 'arrayList is no multidimensional';
    }
    

提交回复
热议问题