Several commonly used empty removal, grouping, and debugging array functions in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:48:10
Original
1009 people have browsed it

dump() converts the array into an array format, which is useful for debugging
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() removes empty elements from the array
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 default function is to group functions evenly

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319779.htmlTechArticledump() Array the array in array format, which is useful for debugging function dump($vars, $label = '' , $return = false){ if (ini_get('html_errors')) { $content = "pren"; if ($label != '') { $co...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template