Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/163.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_Api - Fatal编程技术网

如何在PHP中输出特定数组?

如何在PHP中输出特定数组?,php,api,Php,Api,我尝试从API编写输出代码 所以我先拿了这个: $api_response = json_decode(file_get_contents("--LINK TO API--")); 如果我var_转储$api_响应 object(stdClass)#1 (3) { ["status"]=> string(2) "ok" ["count"]=> int(1) ["data"]=> array(1) { [0]=> object(st

我尝试从API编写输出代码

所以我先拿了这个:

$api_response = json_decode(file_get_contents("--LINK TO API--"));
如果我var_转储$api_响应

object(stdClass)#1 (3) {
  ["status"]=>
  string(2) "ok"
  ["count"]=>
  int(1)
  ["data"]=>
  array(1) {
    [0]=>
    object(stdClass)#2 (4) {
      ["clan_id"]=>
      int(1000001876)
      ["nickname"]=>
      string(10) "JakenVeina"
      ["id"]=>
      int(1001147659)
      ["account_id"]=>
      int(1001147659)
    }
  }
}
因此,如果我只想输出帐户id,我尝试了更多的方法:

$account_id = $api_response["data"]["account_id];
echo $account_id;

对我来说什么都不管用。
有人有主意吗?

你不是在要求对数组进行解码

您需要(注意真实情况):

然后,您应该能够根据需要访问数组键


另外,
account\u id
比您指定的低一个子级别。

您不是要求
json\u decode
解码到数组

您需要(注意真实情况):

然后,您应该能够根据需要访问数组键


另外,
account\u id
比您指定的低一个子级。

结果的第一级是
stdclass
,因此您必须使用
->
来获取
数据
数组。然后,数据是一个数组,您可以使用
[]
访问其成员

要获取您的帐户id,您可以使用:

$account_id = $api_response->data['account_id'];

结果的第一级是
stdclass
,因此必须使用
->
来获取
数据
数组。然后,数据是一个数组,您可以使用
[]
访问其成员

要获取您的帐户id,您可以使用:

$account_id = $api_response->data['account_id'];

您有一个对象数组,因此需要像对象一样访问它,对于数值,需要使用
{}
,否则无法访问它

$api_response->data->{0}->account_id; //1001147659
您还可以使用
json_decode
中的
true
作为第二个参数来执行相同的操作。如果您在其中执行此操作,您的数组将转换为关联数组,您可以通过以下方式访问它:

$api_response['data'][0]['account_id']; //1001147659

两者都将产生相同的结果。

您有一个对象数组,因此需要像对象一样访问它,对于数值,您需要使用
{}
,否则无法访问它

$api_response->data->{0}->account_id; //1001147659
您还可以使用
json_decode
中的
true
作为第二个参数来执行相同的操作。如果您在其中执行此操作,您的数组将转换为关联数组,您可以通过以下方式访问它:

$api_response['data'][0]['account_id']; //1001147659

两者都会产生相同的结果。

不知道这是这里的输入错误还是您的代码中的输入错误,但您在
$account\u id=$api\u response[“data”][“account\u id]的末尾缺少一个”不知道是这里还是代码中的输入错误,但在
$account\u id=$api\u response[“data”][“account\u id]”的末尾缺少一个“输入错误”谢谢。这是可行的,但我还有一个问题。仅当我将[0]放入account\u id变量时,它才起作用。这是干什么用的?请参阅:$account_id=$api_response['data'][0]['account_id']//编辑得到它,谢谢:)因为
['data']
是一个数组。这是可行的,但我还有一个问题。仅当我将[0]放入account\u id变量时,它才起作用。这是干什么用的?请参阅:$account_id=$api_response['data'][0]['account_id']//编辑得到它,谢谢:)因为
['data']
是一个数组,谁给
下一票???这件事是谁干的??请告诉我为什么。谁投了否决票???这件事是谁干的??请告诉我为什么。