You are looking for the array_filter function; -)
For example, this piece of code:
$arr = array(null, 0, null, 0, '', null, '', 4, 6, '', ); $arr_filtered = array_filter($arr); var_dump($arr_filtered);
It produces the following result:
array 7 => int 4 8 => int 6
Please note that all false values ββhave been deleted.
And if you want to be more specific, you can specify your own filter function. For example, to remove only null from an array, I could use this:
function my_filter($item) { if ($item === null) { return false; } return true; } $arr = array(null, 0, null, 0, '', null, '', 4, 6, '', ); $arr_filtered = array_filter($arr, 'my_filter'); var_dump($arr_filtered);
And I get:
array 1 => int 0 3 => int 0 4 => string '' (length=0) 6 => string '' (length=0) 7 => int 4 8 => int 6 9 => string '' (length=0)