Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.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 stdClass如何在';它也在一个数组中吗?_Php_Facebook Graph Api_Stdclass - Fatal编程技术网

PHP stdClass如何在';它也在一个数组中吗?

PHP stdClass如何在';它也在一个数组中吗?,php,facebook-graph-api,stdclass,Php,Facebook Graph Api,Stdclass,我有这样的东西。我正在尝试从数组的数组中获取id。。。这让我有点困惑 Array ( [data] => Array ( [0] => stdClass Object ( [name] => name [id] => 123 ) ) 但如何从数组[数据]中获取该数组呢 如果第一个数组位于名为$arra

我有这样的东西。我正在尝试从数组的数组中获取id。。。这让我有点困惑

Array
 (
    [data] => Array
         (
           [0] => stdClass Object
            (
                [name] => name
                [id] => 123
            )

    )
但如何从数组[数据]中获取该数组呢


如果第一个数组位于名为
$array
的变量中,则表示感谢

您的数组
$array
'data'
键中包含另一个数组

因此,要检索第二个数组,可以执行以下操作:

To get the id: echo $array[0]->id;
$second\u数组
0
键中包含一个对象。您可以检索此对象,如您所说:

$second_array = $array['data']; //this will return the second array
然后从
$obj

$obj = $second_array[0];
要在一行中获取
id

$obj->id;

$array['data'][0]->id尝试$array[“data”][0]->我想为你的两个答案投票,但它只允许我投票一次。谢谢你们!我错过的只是一件愚蠢的事情谢谢。你知道我是否需要在foreach循环中完成吗?我不太明白。正如@Khushboo所说,你不需要一个循环来检索对象。如果有更多的id和名称,我会需要一个循环吗?还有@krichprollsch,非常感谢!解释得很好!!!谢谢你耐心地用我能理解的这么小的步骤来解释:)你的意思是如果第二个数组中有更多的对象?这取决于你想做什么。但我想是的,你需要一个循环。您可以执行
foreach($array['data']as$obj){echo$obj->id;}
$array['data'][0]->id; //will return the attr id from the object