亲宝软件园·资讯

展开

php 去空、分组、调试数组 php下几个常用的去空、分组、调试数组函数

人气:0
想了解php下几个常用的去空、分组、调试数组函数的相关内容吗,在本文为您仔细讲解php 去空、分组、调试数组的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:php,去空,分组,调试数组,下面大家一起来学习吧。
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;
}
}
}
}
array_chunk() php默认函数 作用是把函数平均分组

加载全部内容

相关教程
猜你喜欢
用户评论