PHP访问数组

0 php arrays wordpress

我有点困惑.

我有一个数组:

<?php 

$terms = get_the_terms($post->ID, 'pf');
        print_r($terms);
?>
Run Code Online (Sandbox Code Playgroud)

它输出:

数组([15] => stdClass对象([term_id] => 15 [名称] =>文本[slug] => text [term_group] => 0 [term_taxonomy_id] => 33 [分类法] => pf [描述] = > PF文章.[parent] => 0 [count] => 3 [object_id] => 694))

我只想输出slug(在这种情况下为"text")而不是整个数组.

所以我在做:

<?php $terms = get_the_terms($post->ID, 'pf');
             echo $terms["slug"]; ?>
Run Code Online (Sandbox Code Playgroud)

它什么也没输出.

这也没有结果:

echo "{$terms['slug']}";
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

更新!!!

我不能使用$ term [15] - > slug,因为我的脚本将基于[分类法](在这种情况下为pf)!:)所以没有foreach循环就不可能做到这一点?

Sha*_*ngh 5

术语数组15索引包含这样的对象访问

echo $term[15]->slug
Run Code Online (Sandbox Code Playgroud)