gpt4 book ai didi

PHP 数组 stdClass 对象 - 回显值

转载 作者:行者123 更新时间:2023-12-02 22:56:44 25 4
gpt4 key购买 nike

所以我将此数组保存在变量标题$arr中。我想获取或回显 [slug] 的值

Array ( [0] => stdClass Object ( [term_id] => 11 
[name] => Community Service
[slug] => community-service
[term_group] => 0
[term_taxonomy_id] => 11
[taxonomy] => category

所以我想要这样的东西

echo $arr[slug]

然后将显示“community-service”。我确信这是非常简单的事情,但我不知道如何从数组 stdClass 中获取值并将其回显在页面上。谢谢。

最佳答案

数组$arr包含1个对象。您必须使用 -> 语法来访问它的属性。

echo $arr[0]->slug;

关于PHP 数组 stdClass 对象 - 回显值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10688650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com