Php 显示返回对象的值

Php 显示返回对象的值,php,arrays,object,Php,Arrays,Object,我有一个变量对象,它存储下面的值 Array ( [0] => stdClass Object ( [term_id] => 1 [name] => Uncategorized [slug] => uncategorized [term_group] => 0 [term_taxonomy_id] => 1

我有一个变量对象,它存储下面的值

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的数组中:


您可以使用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

更新后的代码可能重复,请重试,如果无法正常工作,可能需要显示更多的代码。这是正确的方法。如果这不起作用,请发布更多代码,因为它对于给定的信息是正确的。
echo $obj->slug