gpt4 book ai didi

php - 使用 PHP 访问对象的属性

转载 作者:可可西里 更新时间:2023-11-01 01:03:03 25 4
gpt4 key购买 nike

我正在尝试使用 PHP 访问对象的一部分。我能够访问某些部分,但是,当我尝试访问包含信用卡号最后 4 位数字的部分时,它只会打印出 NULL。这是我的代码:

$customer = Braintree_Customer::find('51658462');
echo var_dump($customer);

这将打印出对象。这是打印出来的一部分:

object(Braintree_Customer)#1 (1) {
["_attributes"]=>
array(14) {
["id"]=>
string(8) "51658462"
["merchantId"]=>
string(16) "tyn83x4j454dnvmt"
["firstName"]=>
string(4) "Demo"
["lastName"]=>
string(7) "Account"
["company"]=>
NULL
["phone"]=>
string(12) "555-555-5555"
["fax"]=>
NULL
["website"]=>
NULL
["createdAt"]=>
object(DateTime)#8 (3) {
["date"]=>
string(19) "2013-08-14 15:19:26"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
["updatedAt"]=>
object(DateTime)#9 (3) {
["date"]=>
string(19) "2013-08-14 15:19:27"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
["customFields"]=>
string(3) "
"
["creditCards"]=>
array(1) {
[0]=>
object(Braintree_CreditCard)#2 (1) {
["_attributes"]=>
array(29) {
["bin"]=>
string(6) "371275"
["expirationMonth"]=>
string(2) "01"
["expirationYear"]=>
string(4) "2016"
["last4"]=>
string(4) "1234"

我正在尝试访问 last4 属性。我尝试了几种不同的方法,但都不起作用。我认为 echo var_dump($customer->creditCards->last4); 会给我值,但事实并非如此。我错过了什么?

最佳答案

var_dump($customer->creditCards[0]->last4);

creditCards 是一个包含一项的数组 — 仅供引用,您不需要echo var_dump 的结果。

关于php - 使用 PHP 访问对象的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18241987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com