Checking if array is multidimensional or not?

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

    is_array($arr[key($arr)]); 
    

    No loops, plain and simple.

    Works also with associate arrays not only numeric arrays, which could not contain 0 ( like in the previous example would throw you a warning if the array doesn't have a 0. )

提交回复
热议问题