我有两个阵列-卡和令牌,我想将一个放入另一个阵列:
{
"cards": [
{
"CardNumber": "xxxxxx******xxxx",
"Holder": "EUEUEUEUEUEU",
"ExpirationDate": "xx/xxxxx"
},
{
"CardNumber": "xxxxxx******xxxx",
"Holder": "EU",
"ExpirationDate": "xx/xxxxx"
}
]
}
{
"tokens": [
{
"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
]
如何将第二个数组插入第一个数组,如下所示:
{
"cards": [
{
"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"CardNumber": "xxxxxx******xxxx",
"Holder": "EUEUEUEUEUEU",
"ExpirationDate": "xx/xxxxx"
},
{
"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"CardNumber": "xxxxxx******xxxx",
"Holder": "EU",
"ExpirationDate": "xx/xxxxx"
}
]
}
我正在使用以下代码获取纸牌阵列。 $ token返回令牌值:
foreach ($token_values as $token) {
$request[] = getCards($merchantId, $merchantKey, $token);
}
$arrayJSON['cards'] = $request;
echo json_encode($arrayJSON);
答案 0 :(得分:4)
您应该能够在token
循环内添加foreach
值:
foreach ($token_values as $token) {
$request[] = array_merge(array('token' => $token), getCards($merchantId, $merchantKey, $token));
}