嵌套foreach,首先根据单据id(billId)遍历出对应单据下对应的明细列表,例如$v2='00001'和'00002',然后根据得到的明细数据(例如00001下有50条记录,00002下有60条记录),输出表格,但是得到的结果总是00002下的60条记录,怎么把两次遍历的结果拼接在一起呢?
foreach ($danju as $k2 => $v2){
$url_mingxi="http://xxxx.xxxx.com/purOrder/getOrderDetailInfo.action?billId=$v2";
$arr_mingxi=curl_get($url_mingxi,$cookie_jar,$UserAgent);
foreach($arr_mingxi as $keys => $values){
$html .= "<tr><td>{$arr_mingxi[$keys]['spbmhx']}</td><td>{$arr_mingxi[$keys]['pluCode']}</td><td>{$arr_mingxi[$keys]['pluName']}</td></tr>";
}
}
echo $html;
黄舟2017-05-16 13:17:04
建议你把内层代码封装起来,然后再去输出,参考下面代码
function getData($id){
$html = '';
$url_mingxi="http://xxxx.xxxx.com/purOrder/getOrderDetailInfo.action?billId=". $id;
$arr_mingxi=curl_get($url_mingxi,$cookie_jar,$UserAgent);
if($arr_mingxi){
foreach($arr_mingxi as $keys => $values){
$html .= "<tr><td>{$arr_mingxi[$keys]['spbmhx']}</td><td>{$arr_mingxi[$keys]['pluCode']}</td><td>{$arr_mingxi[$keys]['pluName']}</td></tr>";
}
}
return $html;
}
$rs = '';
foreach ($danju as $k2 => $v2){
$rs .= getData($v2);
}
echo $rs;