侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

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

2023-12-12 星期二 / 0 评论 / 0 点赞 / 49 阅读 / 989 字

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

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默认函数 作用是把函数平均分组

广告 广告

评论区