Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:从多数组中获取值_Php_Arrays - Fatal编程技术网

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}”;}
将回显它。我只是想解释一下,我不知道你的具体用法。