dongpao1873 2010-09-07 23:47
浏览 172
已采纳

PHP foreach堆栈 - 在调用下一个迭代时,每个循环中调用的函数是否仍然可以运行

I am having problems with cURL not being able to connect to a server that returns an xml feed and am not sure if my code is stacking up and causing the problem. Is it possible the final function called in this foreach loop is still running when the next loop iteration comes round.

Is it possible to make sure all functions in the loop complete before the next iteration begins, or does foreach do this by default anyway? I tried setting a return true on process_xml() and running a test in the loop: if($this->process_xml($xml_array))continue; but it didn't seem to have an effect and seems like a bad idea anyway.

foreach($arrayOfUrls as $url){

    //retrieve xml from url as string.
    if($url_xml_string = $this->getFeedStringUsing_cURL($url)){
        $xml_object = simplexml_load_string($url_xml_string);
        $xml_array = $this->feedStringToArray($xml_object);
        //process the xml.
        $this->process_xml($xml_array);
    }                                 
}
  • 写回答

2条回答 默认 最新

  • douliaotong4944 2010-09-07 23:49
    关注

    No, this is not possible. Each statement is executed and finished before the next statement is run.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部