How to check if a multidimensional array is empty or not?

前端 未结 6 1268
[愿得一人]
[愿得一人] 2021-02-01 05:20

Basically, I have a multidimensional array, and I need to check whether or not it is simply empty, or not.

I currently have an if statement trying to do thi

6条回答
  •  北荒
    北荒 (楼主)
    2021-02-01 06:02

    You can filter the array, by default this will remove all empty values. Then you can just check if it's empty:

    $filtered = array_filter($csv_array);
    if (!empty($filtered)) {
      // your code
    }
    

    Note: This will work with the code posted in your question, if you added another dimension to one of the arrays which was empty, it wouldn't:

    $array = array(array()); // empty($filtered) = true;
    $array = array(array(array())); // empty($filtered) = false;
    

提交回复
热议问题