首页  >  文章  >  后端开发  >  php下几个常用的去空、分组、调试数组函数_PHP教程

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

WBOY
WBOY原创
2016-07-21 15:48:10956浏览

dump() 把数组以数组格式数组,有益于调试
function dump($vars, $label = '', $return = false){
if (ini_get('html_errors')) {
$content = "

\n"; <br>if ($label != '') { <br>$content .= "<strong>{$label} :</strong>\n"; <br>} <br>$content .= htmlspecialchars(print_r($vars, true)); <br>$content .= "\n
\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默认函数 作用是把函数平均分组

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/319779.htmlTechArticledump() 把数组以数组格式数组,有益于调试 function dump($vars, $label = '', $return = false){ if (ini_get('html_errors')) { $content = "pre\n"; if ($label != '') { $co...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn