PHP:从多数组中获取值
我正在尝试从数组中检索值。代码如下: 我有这样一个数组:PHP:从多数组中获取值,php,arrays,Php,Arrays,我正在尝试从数组中检索值。代码如下: 我有这样一个数组: $video_categories = get_the_terms( get_the_ID(), 'videos_cat', ', ' ); 打印结果时: Array ( [22] => stdClass Object ( [term_id] => 22 [name] => فيديو
$video_categories = get_the_terms( get_the_ID(), 'videos_cat', ', ' );
打印结果时:
Array
(
[22] => stdClass Object
(
[term_id] => 22
[name] => فيديو
[slug] => videos
[term_group] => 0
[term_taxonomy_id] => 47
[taxonomy] => videos_cat
[description] =>
[parent] => 0
[count] => 383
[object_id] => 26138
[filter] => raw
),
[23] => stdClass Object
(
[term_id] => 23
[name] => العاب
[slug] => videos
[term_group] => 0
[term_taxonomy_id] => 47
[taxonomy] => videos_cat
[description] =>
[parent] => 0
[count] => 383
[object_id] => 26138
[filter] => raw
)
)
如何获取变量中的
term\u id
值以打印它?以正常方式访问数组的索引数组[index]
。它包含一个对象,因此您需要使用对象操作符来访问它的属性和方法,如object->property
或object->method()
从你看起来正在做的事情来看,应该是这样的:
echo $categories[22]->term_id;
今天已经有两个问题问如何访问数组对象!请学习基本知识并阅读手册,它不太难,手册也不咬人!我假设你知道你要找的索引。您可以轻松地在数组上循环以查找每个对象的属性。
foreach(数组为$index=>$value){echo“{$value->term_id}for index{$index}”;}
将回显它。我只是想解释一下,我不知道你的具体用法。