【发布时间】:2022-01-28 03:00:40
【问题描述】:
我在数组中插入变量时遇到问题。这是数组:
[
'body' => '{"data":{"attributes":{"details":{"card_number":"4343434343434345","exp_month":12,"exp_year":24,"cvc":"123"},"billing":{"name":"Test Man ","email":"test@test.com","phone":"1234567"},"type":"card"}}}',
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Basic c2tfdGVzdF9mcUNRUmd4NVVUOEJhRHhEYnNHM2lOVm86',
'Content-Type' => 'application/json',
],
]
我需要做的是将card_number、exp_month、exp_year 等替换为用户提交的值。我尝试了很多方法来替换像这样的值:
[
'body' => '{"data":{"attributes":{"details":{"card_number":"{$request->cardNumber}","exp_month":{$request->cardMonth},"exp_year":{$request->cardyear},"cvc":"{$request->cardCVC}"},"billing":{"name":"{$request->name}","email":"{$request->email}","phone":"{$request->phone}"},"type":"card"}}}',
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Basic c2tfdGVzdF9mcUNRUmd4NVVUOEJhRHhEYnNHM2lOVm86',
'Content-Type' => 'application/json',
],
]
不幸的是,没有读取变量。任何帮助表示赞赏。谢谢。
【问题讨论】: