dump() 把数组以数组格式数组,有益于调试
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()去除数组中为空的元素
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;
}
}
}
}
本文介绍了PHP中的两个实用函数:dump()用于以数组格式输出变量,便于调试;array_remove_empty()用于从数组中移除空元素。这两个函数对于PHP开发者来说非常有用。

被折叠的 条评论
为什么被折叠?



