工具函数 array_dump()
类似于var_dump() 区别在于它可以把输出当成字符串返回,而不是直接打印
1
function array_dump( $var ) {
2
3
$resString = "" ;
4
// The gettype function returns the data type
5
// of its parameter.
6
switch ( gettype ( $var )) {
7
8
// inter, double, and strings are simply
9
// displayed.
10
case ' integer ' :
11
case ' double ' :
12
case ' string ' :
13
$resString .= " $var\n " ;
14
break ;
15
16
// array datatypes need to specially
17
// handled.
18
case ' array ' :
19
$resString .= " Array\n(\n " ;
20
// if the array has no entries, display
21
// a message.
22
if ( ! Count ( $var )) {
23
$resString .= " \tEmpty Array.\n " ;
24
}
25
else {
26
27
28
// use a do loop to iterate over the
29
// entries in the array.
30
do {
31
$resString .= " \t[ " . key ( $var ) . " ] => " ;
32
33
// perform the magic of recursion using the
34
// VALUE of the current key/value pair.
35
$resString .= array_dump( $var [ key ( $var )]);
36
} while ( next ( $var ));
37
38
// end the HTML table after all of the
39
//array entries have been displayed.
40
}
41
$resString .= " )\n " ;
42
break ;
43
44
// switch statements should always have a default
45
// clause - just in case the data has a value
46
// your program doesn't expect.
47
default :
48
$resString .= " unknown data type\n " ;
49
break ;
50
}
51
return $resString ;
52
}

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

42

43

44

45

46

47

48

49

50

51

52

热门日志
分类
- Django(4)
- ssdb(1)
- Mac(7)
- C(1)
- memcache(1)
- Python(32)
- Vim(8)
- sed(2)
- ansible(3)
- awk(4)
- shell(3)
- about(1)
- git(9)
- bat(4)
- svn(0)
- docker(1)
- Tornado(1)
- go(2)
- 架构(18)
- Vue(1)
- game(2)
- Html(6)
- Java(8)
- Mysql(37)
- Ajax(2)
- Jsp(1)
- Struts(8)
- Linux(72)
- JavaScript(39)
- Staruml(0)
- Mouth(1)
- Php(102)
- Windows(8)
- Message(48)
- Lua(10)
- Compute(1)
- Redis(7)
- Nginx(12)
- Jquery(1)
- Apache(1)
- cocos2d-x(8)