我有以下数组:
["entity_id"] => "1"
["customer_id"] => "18"
["public_hash"] => "xxxxxxxxxx041e6f5246f041429424422795137118223d73bb6197410f9cbc77"
["payment_method_code"] => "braintree"
["type"] => "card"
["created_at"] => "2018-12-19 21:24:13"
["expires_at" => "2020-06-01 00:00:00" "gateway_token"] => "8cx9y7"
["details"] => "{"type":"AE","maskedCC":"0005","expirationDate":"05\\\\\\\\/2020"}"
["is_active"] => "1"
["is_visible"] => "1"
我正在尝试分别从 ["details"]
获取值(类型、maskedCC、expirationDate)
使用 $details = $card->getData('details'); 我可以将范围缩小到:
{"type":"AE","maskedCC":"0005","expirationDate":"05\/2020"}
从那里,我不确定如何获取值 AE, 0005, 05/2020。
最佳答案
您正在处理一个 jsonObj。 您必须先将其解码为数组。 $key 将是您想要获取的属性,例如(类型、maskedCC、expirationDate)
$jsonArray = json_decode($details,true);
echo $jsonArray[$key];
关于PHP:从数组中的字符串获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54599970/