我有一个变量对象来存储下面的值。
Array
(
[0] => stdClass Object
(
[term_id] => 1
[name] => Uncategorized
[slug] => uncategorized
[term_group] => 0
[term_taxonomy_id] => 1
[taxonomy] => category
[description] =>
[parent] => 0
[count] => 4
[object_id] => 39
[cat_ID] => 1
[category_count] => 4
[category_description] =>
[cat_name] => Uncategorized
[category_nicename] => uncategorized
[category_parent] => 0
)
)
现在我想显示值列表中的slug
。我该怎么做?
假设对象存储在名为$array
的数组中:
echo $array[0]->slug
您可以使用print_r($yourObject)打印出整个对象用于调试,或者如果您只想打印该值,这将起作用:echo($yourObject[0]->slug);.
如果有多个数组下标,则:
foreach($yourObject as $object)
{
echo $object->slug;
}
约翰给了你一个确切的答案…让我解释一下
$obj = your_array;//from where you are using var_dump() to see these values..
和
echo $obj->slug
您可以对转储中的其他术语使用相同的技术,例如
echo $obj->name
HTH