function getObjectVarNames($object, $name = '')
{
$objectVars = get_object_vars($object);
$objectVarNames = array();
foreach ($objectVars as $key => $objectVar) {
if (is_object($objectVar)) {
$objectVarNames = array_merge($objectVarNames, getObjectVarNames($objectVar, $name . $key));
continue;
}
$objectVarNames[] = $name . $key;
}
return $objectVarNames;
}
$o = new stdClass();
$o->f1 = new stdClass();
$o->f2 = 2;
$o->f1->f12 = 5;
$o->f1->f13 = "hello world";
var_export(getObjectVarNames($o));
结果:
array (
0 => 'f1f12',
1 => 'f1f13',
2 => 'f2',
)
你尝试过什么? – 2014-10-22 11:25:06
有什么特定的技术原因,你为什么需要这个?可能有更好的选择,或更好的设计来实现您的实际业务目标 – 2014-10-22 11:30:05