简体   繁体   中英

Filter Empty/Null value from associative array in php (multidimensional array)

I want to remove null rows from assoctivate array, ie whose values are empty

Already Check

 array[0]
      a =>  '101'
      b =>  '105'
      c =>  '103'

 array[1]
      a =>  ''
      b =>  ''
      c =>  ''

 array[2]
      a =>  '101'
      b =>  '105'
      c =>  '103'

 Desired result :- 

  array[0]
      a =>  '101'
      b =>  '105'
      c =>  '103'  

 array[1]
      a =>  '101'
      b =>  '105'
      c =>  '103'

Note :- This is a Subarray of array.ie Multidimensional array.

As went through many post, I found simplest answer

//foreach

if (strlen(implode('', array_values($array_row))) > 0) {


}

This will not let empty row

You can filter using implode .

$non_empty_rows = array_filter($array, 'implode');

That will collapse multiple null values or empty strings in each sub-array into a single empty string which will evaluate as false.

Runnable example at 3v4l.org

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM