1

真的需要一种将我的实体转换为数组的方法。我知道可以手动完成,但是对每个实体进行操作很痛苦,更多地处理关系并不容易。

你好吗?你有没有实施过这样的事情?

4

1 回答 1

2

您可以使用get_class_methods以下方法查找吸气剂:

function toArray($object)
{
    $result = array();
    $methods = get_class_methods($object);
    foreach($methods as $method) {
        if ('get' == substr($method, 0, 3)) {
            $result[substr($method, 3)] = $object->$method();
        }
    }
    return $result;
}
于 2011-08-10T07:28:13.243 回答