php 数组去除空值

时间:2023-03-09 01:12:16
php 数组去除空值
	/**
* 方法库-数组去除空值
* @param string $num 数值
* @return string
*/
public function array_remove_empty(&$arr, $trim = true) {
if (!is_array($arr)) return false;
foreach($arr as $key => $value){
if (is_array($value)) {
self::array_remove_empty($arr[$key]);
} else {
$value = ($trim == true) ? trim($value) : $value;
if ($value == "") {
unset($arr[$key]);
} else {
$arr[$key] = $value;
}
}
}
}