php访问属性两种方式,使用PHP访问对象的属性

我正在尝试使用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是一个包含一项的数组-仅供参考,您无需回显var_dump的结果.

标签:braintree,arrays,php,object

来源: https://codeday.me/bug/20191030/1968657.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值