n"; if ($label != '') { $content .= "{$label} :
n"; if ($label != '') { $content .= "{$label} :
Home >Backend Development >PHP Tutorial >Array functions: Several commonly used empty removal, grouping, and debugging array functions in PHP dump() converts the array into an array format, which is useful for debugging
The above introduces the array functions and several commonly used denulling, grouping, and debugging array functions in PHP, including the content of array functions. I hope it will be helpful to friends who are interested in PHP tutorials.
Array functions: Several commonly used empty removal, grouping, and debugging array functions in PHP
function dump($vars, $label = '', $return = false){
if (ini_get('html_errors')) {
$content = "< pre>n";
if ($label != '') {
$content .= "{$label} :n";
}
$content .= htmlspecialchars(print_r( $vars, true));
$content .= "nn";
} 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 The function is to group the functions evenly
Related articles
See more