显示返回对象的值

时间:2013-03-02 18:52:13

标签: php arrays object

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

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。我该怎么做?

3 个答案:

答案 0 :(得分:5)

假设该对象存储在名为$array的数组中:

echo $array[0]->slug

答案 1 :(得分:1)

您可以使用print_r($ yourObject)打印整个对象以进行调试,或者如果您只想打印该值,则可以使用:echo($ yourObject [0] - > slug);

如果有多个数组索引,那么:

foreach($yourObject as $object)
{
    echo $object->slug;
}

答案 2 :(得分:1)

Jonh给了你一个确切的答案......让我解释一下

$obj = your_array;//from where you are using var_dump() to see these values..

然后

echo $obj->slug

您可以对转储中的其他术语使用相同的技术,例如

echo $obj->name

HTH