Home >php教程 >php手册 >php object转数组示例

php object转数组示例

WBOY
WBOYOriginal
2016-06-06 20:25:411114browse

这篇文章主要介绍了php object转数组的示例,代码简单,可以直接看下面的代码

复制代码 代码如下:


function std_class_object_to_array($stdclassobject)
{
    $_array = is_object($stdclassobject) ? get_object_vars($stdclassobject) : $stdclassobject;

    foreach ($_array as $key => $value) {
        $value = (is_array($value) || is_object($value)) ? std_class_object_to_array($value) : $value;
        $array[$key] = $value;
    }

    return $array;
}

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