【发布时间】:2016-09-17 13:10:52
【问题描述】:
我有一个 foreach 循环,它工作正常 - 但由于某种原因,在它发生后任何超出循环的东西都不会输出。例如 echo $cpaTotal;不显示任何内容。
For 循环输出完美
我哪里出错了?
$key = '84abf';
$from = '2016/7/1';
$to = '2016/9/17';
$url = '/api/affreporting.asp?key='.$key.'&reportname=QuickSummaryReportDetailed&reportformat=xml&reportmerchantid=0&reportstartdate='.$from.'&reportenddate='.$to;
$clean_xml = str_ireplace(['SOAP-ENV:', 'SOAP:'], '', file_get_contents($url));
$xml = simplexml_load_string($clean_xml);
$obj = json_decode(json_encode($xml));
$cpaTotal = 'test';
foreach($obj->Body->reportresponse->row as $row)
{
$CPACommission = $row->CPACommission;
$merchant = $row->merchantname;
$Product1NetRevenue = $row->Product1NetRevenue;
echo "Merchant: ".$merchant. " | ";
echo "CPA Commission: ".$CPACommission." | ";
echo "Net Revenue: ".$Product1NetRevenue."</br>";
echo "<hr>";
}
echo $cpaTotal;
输出 (html)
Merchant: <strong>mFortune</strong> | CPA Commission: <strong> £2270</strong> | Downloads: <strong>34</strong> | Net Revenue: <strong>£-161.4</strong><br>Merchant: <strong>PocketWin</strong> | CPA Commission: <strong> £1330</strong> | Downloads: <strong>22</strong> | Net Revenue: <strong>£-134.77</strong><br>Merchant: <strong>Mr Spin</strong> | CPA Commission: <strong> £680</strong> | Downloads: <strong>31</strong> | Net Revenue: <strong>£13.22</strong><br>
【问题讨论】:
-
你没有设置 $cpaTotal
-
我不明白为什么这不起作用,而且它不起作用也没有任何意义。您需要向我们提供minimal reproducible example。
-
抱歉刚刚更新 where $cpaTotal = 'test';包括
-
什么是?
-
我已添加完整代码 - 显然 URL 不起作用,我不得不更改密钥