Heim  >  Artikel  >  Backend-Entwicklung  >  几个常用的去空、分组、调试数组函数_PHP教程

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

WBOY
WBOYOriginal
2016-07-13 17:37:34868Durchsuche

dump() 把数组以数组格式数组,有益于调试

 
function dump($vars, $label = , $return = false){
    if (ini_get(html_errors)) {
        $content = "
";<br>
        if ($label != ) {<br>
            $content .= "<strong>{$label} :</strong>
";<br>
        }<br>
        $content .= htmlspecialchars(print_r($vars, true));<br>
        $content .= "
";
    } else {
        $content = $label . " : " . 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/486547.htmlTechArticledump() 把数组以数组格式数组,有益于调试 function dump($vars, $label = , $return = false){ if (ini_get(html_errors)) { $content = pre; if ($label != ) { $content .=...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn