轻轻走过
我似风中落叶
posts - 2, comments - 0, trackbacks - 0, articles - 0
PHP博客
::
首页
::
新随笔
::
联系
::
聚合
::
管理
工具函数array_dump()
Posted on 2006-08-05 19:19
轻轻走过
阅读(758)
评论(0)
编辑
收藏
引用
网摘
类似于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
}
只有注册用户
登录
后才能发表评论。
网站导航:
IT新闻
博客园
BlogJava
博客生活
IT博客网
C++博客
程序员招聘
Powered by:
PHP博客
Copyright © 轻轻走过
日历
<
2006年8月
>
日
一
二
三
四
五
六
30
31
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
1
2
3
4
5
6
7
8
9
留言簿
(1)
给我留言
查看公开留言
查看私人留言
随笔档案
2006年8月 (2)
搜索
最新评论
阅读排行榜
1. 工具函数array_dump()(758)
2. 第一篇:感觉不错(263)
评论排行榜
1. 第一篇:感觉不错(0)
2. 工具函数array_dump()(0)