我有两个数组,其中包含conversion_offer_id,转换和&支付。现在我想将它与另一个数组匹配,并将第一个数组的所有值添加到第二个数组,如果没有,则添加转换值&支付为0。
数组1($ conversions)
[
{
"conversion_offer_id": 90,
"conversions": 15,
"payout": 225
},
{
"conversion_offer_id": 196,
"conversions": 1,
"payout": 120
},
{
"conversion_offer_id": 720,
"conversions": 53,
"payout": 1590
}
]
数组2($ clkcs)
[
{
"clicks": 142,
"offer_currency": 45,
"click_offer_id": 90,
"click_affiliate_id": 9106,
"offer_name": "BKS",
"offer_id": 90,
"currency_symbol": "₹"
},
{
"clicks": 8,
"offer_currency": 45,
"click_offer_id": 196,
"click_affiliate_id": 9106,
"offer_name": "FFU",
"offer_id": 196,
"currency_symbol": "₹"
},
{
"clicks": 1,
"offer_currency": 45,
"click_offer_id": 246,
"click_affiliate_id": 9106,
"offer_name": "GFT",
"offer_id": 246,
"currency_symbol": "₹"
},
{
"clicks": 1,
"offer_currency": 45,
"click_offer_id": 334,
"click_affiliate_id": 9106,
"offer_name": "JPR",
"offer_id": 334,
"currency_symbol": "₹"
},
{
"clicks": 1,
"offer_currency": 45,
"click_offer_id": 622,
"click_affiliate_id": 9106,
"offer_name": "TWS",
"offer_id": 622,
"currency_symbol": "₹"
},
{
"clicks": 1197,
"offer_currency": 45,
"click_offer_id": 720,
"click_affiliate_id": 9106,
"offer_name": "KPS",
"offer_id": 720,
"currency_symbol": "₹"
}
]
我实现的逻辑
foreach($clkcs as $k=>$key){
foreach($conversions as $ckey){
if($key['click_offer_id']==$ckey['conversion_offer_id']){
$clkcs[$k]['offer_id']=$ckey['conversion_offer_id'];
$clkcs[$k]['conversions']=$ckey['conversions'];
$clkcs[$k]['payout']=$ckey['payout'];
}else{
$clkcs[$k]['conversions']='0';
$clkcs[$k]['payout']='0';
}
}
}
转化&只支付最后匹配值的支出正好填写。剩下的就是0。
但它也应该添加转换&报价ID为90& 196。
我做错了什么?
答案 0 :(得分:2)
成功填写$ clkcs
后,您需要停止第二次预告Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is error="access_denied", error_description="Error requesting access token."] with root cause
org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error
答案 1 :(得分:0)
每次访问$ clkcs时重新填充数组。
因此,在下一个第一次运行中为ID 90设置正确的对话后,再次为ID 90设置转换= 0和支付= 0。
现在你应该找到正确的方法:)
如果您希望更快更轻松(并且conversion_offer_id是唯一的),请将其添加为$ conversions [conversion_offer_id]并仅迭代一个数组。