php 通过array_walk调试数组功能实例

内容摘要
这篇文章主要为大家详细介绍了php 通过array_walk调试数组功能实例,具有一定的参考价值,可以用来参考一下。

本范例演示了php中如何通过array_walk调试数组,输出一个可读性良
文章正文

这篇文章主要为大家详细介绍了php 通过array_walk调试数组功能实例,具有一定的参考价值,可以用来参考一下。

本范例演示了php中如何通过array_walk调试数组,输出一个可读性良好的格式,php通过array_walk调试数组的方法,对此感兴趣的朋友,看看idc笔记做的技术笔记。经测试代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<code class="php">
/**
 * 通过array_walk调试数组
 *
 * @param
 * @arrange (www.idcnote.com)
 **/
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('&nbsp;', $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*/
 
 
/***   代码来自php教程(www.idcnote.com)   ***/</code>

注:关于php 通过array_walk调试数组功能实例的内容就先介绍到这里,更多相关文章的可以留意

代码注释

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!