当前位置 : 主页 > 网络编程 > PHP >

对象转数组的函数

来源:互联网 收集:自由互联 发布时间:2021-06-28
object_to_array.php function object_to_array($obj) { $obj = (array)$obj; foreach ($obj as $k = $v) { if (gettype($v) == 'resource') { return; } if (gettype($v) == 'object' || gettype($v) == 'array') { $obj[$k] = (array)object_to_array($v);
object_to_array.php
function object_to_array($obj) {
    $obj = (array)$obj;
    foreach ($obj as $k => $v) {
        if (gettype($v) == 'resource') {
            return;
        }
        if (gettype($v) == 'object' || gettype($v) == 'array') {
            $obj[$k] = (array)object_to_array($v);
        }
    }

    return $obj;
}
网友评论