Nested foreach, first traverse the corresponding detail list under the corresponding document based on the document id (billId), such as $v2='00001' and '00002', and then based on the obtained detailed data (for example, there are 50 records under 00001 , there are 60 records under 00002), the table is output, but the result is always 60 records under 00002. How to splice the results of the two traversals together?
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
It is recommended that you encapsulate the inner code and then output it. Please refer to the code below
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;