PHP幾個(gè)常用的去空、分組、調(diào)試數(shù)組函數(shù)
dump() 把數(shù)組以數(shù)組格式數(shù)組,有益于調(diào)試
function dump($vars, $label = '', $return = false){ if (ini_get('html_errors')) { $content = '<pre>n'; if ($label != '') { $content .= '<strong>{$label} :</strong>n'; } $content .= htmlspecialchars(print_r($vars, true)); $content .= 'n</pre>n'; } else { $content = $label . ' :n' . print_r($vars, true); } if ($return) { return $content; } echo $content; return null;}
array_remove_empty()去除數(shù)組中為空的元素
function array_remove_empty(& $arr, $trim = true){ foreach ($arr as $key => $value) { if (is_array($value)) { array_remove_empty($arr[$key]); } else { $value = trim($value); if ($value == '') { unset($arr[$key]); } elseif ($trim) { $arr[$key] = $value; } } }}
array_chunk() php默認(rèn)函數(shù) 作用是把函數(shù)平均分組
