Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我真的需要一种将我的实体转换为数组的方法。我知道可以手动完成,但是对每个实体进行操作很痛苦,更多地处理关系并不容易。
你好吗?你有没有实施过这样的事情?
您可以使用get_class_methods以下方法查找吸气剂:
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; }