【发布时间】:2013-09-28 23:10:17
【问题描述】:
我得到了下面这段代码的 sn-p,它工作得很好。我一直在分析它,并且这段代码被使用了很多次,所以我想尝试弄清楚如何以一种比当前编写方式更好的方式编写它。
有没有更有效的方法来写这个?
function objectToArray($d) {
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}
if (is_array($d)) {
// Return array converted to object Using __FUNCTION__ (Magic constant) for recursive call
return array_map(__FUNCTION__, $d);
}
else {
// Return array
return $d;
}
}
【问题讨论】:
-
转成json,再转成关联数组?
标签: php performance