关于这个,我似乎有点迷失了方向,我试图解析出一些信息,但stdClass总是在变化,所以我不太确定该怎么做,可以使用come指导。
//查询
$query = new EntityFieldQuery;
$result = $query
->entityCondition('entity_type', 'taxonomy_term')
->propertyCondition('name', 'GOOG')
->propertyCondition('vid', '3')
->execute();//这是输出
Array
(
[taxonomy_term] => Array
(
[1868] => stdClass Object
(
[tid] => 1868
)
)
)现在我可以使用下面的命令来访问tid
$result['taxonomy_term']['1868']->tid但正如前面提到的,stdClass将一直在变化。
发布于 2012-07-02 03:03:35
您可以像这样使用递归数组搜索:
function array_searchRecursive( $needle, $haystack, $strict=false, $path=array() )
{
if( !is_array($haystack) ) {
return false;
}
foreach( $haystack as $key => $val ) {
if( is_array($val) && $subPath = array_searchRecursive($needle, $val, $strict, $path) ) {
$path = array_merge($path, array($key), $subPath);
return $path;
} elseif( (!$strict && $val == $needle) || ($strict && $val === $needle) ) {
$path[] = $key;
return $path;
}
}
return false;
}使用:
$arr = (array) $yourObject;
$keypath = array_searchRecursive('tid', $arr);示例:
$class = new stdClass;
$class->foo = 'foo';
$class->bar = 'bar';
$arr = (array) $class;
$keypath = array_searchRecursive('foo', $arr);
print_r($keypath);结果:
Array
(
[0] => foo
)因此,现在要获取实际值:
echo $keypath[0]; // foohttps://stackoverflow.com/questions/11284826
复制相似问题