Wednesday, 6 December 2017

How to remove null values from an array.


Let say we have an array of

$array = array ( [0] => 0 [1] =>'' [2] => 3 [3] =>'')

we want to remove only null values, not 0(zero)

then we can use this

array_filter($arr, function($var){return !is_null($var);} );

Or we can use array_filter() which will get rid of the null empty values from the array

print_r(array_filter($array, 'strlen'));