Home >php教程 >php手册 >PHP对象转换为数组函数(递归方法)

PHP对象转换为数组函数(递归方法)

WBOY
WBOYOriginal
2016-06-13 12:02:081022browse

返回的是一个层次比较分明的数组对象,希望对大家有所帮助,来源WEB开发笔记(www.chhua.com)。

复制代码 代码如下:


function object_to_array($obj)
{
$_arr = is_object($obj) ? get_object_vars($obj) : $obj;
foreach ($_arr as $key => $val)
{
$val = (is_array($val) || is_object($val)) ? object_to_array($val) : $val;
$arr[$key] = $val;
}
return $arr;
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn