/ Published in: PHP

remove all nulls values in an array
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* * remove null value from array * @param: array $array the array you will be remove the null value * @param: boolean $lessKeys less the keys of array * @return: array the new array */ function array_remove_null($array,$lessKeys = true){ try{ foreach($array as $key => $value){ $NewArray[$key] = $value; }elseif($value){ $NewArray[] = $value; } } return $NewArray; }else{ throw new Exception('array_remove_null() expects parameter 2 to be boolean, ' . gettype( $lessKeys ) . ' given', E_USER_WARNING ); } }else{ throw new Exception('array_remove_null() expects parameter 1 to be array, ' . gettype( $array ) . ' given', E_USER_WARNING ); } }catch(Exception $e){ } }
Comments
