Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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,我使用stripe返回客户对象。我想提取银行帐户ID并将其保存在数据库中以供以后使用。正确访问数组的正确语法是什么 以下是我尝试过的: $bank_account=$customer->lastResponse['json']['sources']['data'][0]['id']; 我被告知尝试: $bank_account=$customer->bank_accounts->data[0]['id']; 但结果也是一样 我不知道如何使用该对象,或者正确的方法是什么。 我

我使用stripe返回客户对象。我想提取银行帐户ID并将其保存在数据库中以供以后使用。正确访问数组的正确语法是什么

以下是我尝试过的:

$bank_account=$customer->lastResponse['json']['sources']['data'][0]['id'];
我被告知尝试:

$bank_account=$customer->bank_accounts->data[0]['id'];
但结果也是一样

我不知道如何使用该对象,或者正确的方法是什么。 我需要
银行账户id
这就是
var\u dump($customer)
在格式化和删除一些不相关的信息后的样子。我想我可以使用JSON解码或访问名为“JSON”的数组。我不知道这两种解决方案的正确语法。请帮忙(:

我认为应该是:

$bank_account = $customer->sources->data[0]->id
如果客户有多个资金来源,您可能需要循环查看
数据
数组以找到您想要的资金来源。
$customer->sources->data[$i]->object
将是
“bank\u account”
,用于您想要的资金来源。

我认为应该是:

$bank_account = $customer->sources->data[0]->id

如果客户有多个资金来源,您可能需要在
数据
数组中循环找到您想要的资金来源。
$customer->sources->data[$i]->object
将是
银行账户
获取所需的源。

非常确定其中有一个getter。您只需使用对象的预期属性即可

例如:

$customer_id = $customer->id;
$bank_account_id = $customer->sources->data[0]->id;

非常确定其中有一个getter。您可以只使用对象上预期的属性

例如:

$customer_id = $customer->id;
$bank_account_id = $customer->sources->data[0]->id;

@kchason Stripe API返回已解码的对象。Stripe API文档位于
\u lastResponse
中,具有领先的UnderStore(
\u
)并且是一个对象。因为它是一个对象,
json
(顺便说一句,这是一个可怕的名称)是它的属性,而不是数组中的索引。您需要:
$customer->\u lastResponse->json['sources']['data'][0]['id']
\u lastResponse
值受保护,可能无法直接访问。如果这不是api提供的值,您可以使用
ReflectionClass
对其进行破解,但如果您发现自己不得不这样做,则通常会使用错误的对象,并且应该使用不同的标识符。很好地掌握了pr受保护的属性。OP读取一些文档的时间到了…@kchason Stripe API返回已解码的对象。Stripe API文档位于
\u lastResponse
,它有一个领先的UnderStore(
\u
)并且是一个对象。因为它是一个对象,
json
(顺便说一句,这是一个可怕的名字)是它的属性,而不是数组中的索引。您需要:
$customer->\u lastResponse->json['sources']['data'][0]['id']
\u lastResponse
值受保护,可能无法直接访问。如果这不是api提供的值,您可以使用
ReflectionClass
对其进行破解,但如果您发现自己不得不这样做,则通常会使用错误的对象,并且应该使用不同的标识符。很好地掌握了pr受保护的属性。OP读取一些文档的时间到了。。。