加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 05:30:18 所属栏目:PHP教程 来源:网络整理
导读:dump() 把数组以数组格式数组,有益于调试 function dump($vars,$label = '',$return = false){ if (ini_get('html_errors')) { $content = " n"; if ($label != '') { $content .= " {$label} : n"; } $content .= htmlspecialchars(print_r($vars,true))

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

n"; 
if ($label != '') {
$content .= "

{$label} :

n";
}
$content .= htmlspecialchars(print_r($vars,true));
$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默认函数 作用是把函数平均分组

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读