|
本范例演示了php中如何通过array_walk调试数组,输出一个可读性良好的格式,php通过array_walk调试数组的方法,感兴趣的小伙伴,下面一起跟随脚本之家 jb51.cc的小编来看看吧。 经测试代码如下:
/**
* 通过array_walk调试数组
*
* @param
* @arrange (512.笔记) jb51.cc
**/
function debug_val($val,$key='',$depth=0) {
if (is_array($val)){
// call this function again with the "sub-array":
array_walk($val,'debug_val',$depth+5);
}
else {
// if we hit a string or bool,etc. then print it:
print str_repeat(' ',$depth);
print '<span style="color: blue;">' . $key . '</span>: ';
print var_export($val,true);
print "<br/>n";
}
}
/*example-start*/
// setup the test array
$array = array(
'php','cool',array('foo',1,2,3,array('mixed' => 'bar')),'php' => 'array','yes' => true,'no' => false
);
// debug the array
debug_val($array);
/*example-end*/
/*** 代码来自脚本之家 jb51.cc(jb51.cc) ***/ (编辑:安卓应用网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|