php - How to merge traversal results in nested foreach?
我想大声告诉你
我想大声告诉你 2017-05-16 13:15:04
0
2
820

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;
我想大声告诉你
我想大声告诉你

reply all(2)
Ty80

Merge in inner loop. Specifically, it means overlapping and merging

黄舟

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;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template