douxu5845 2011-02-26 01:03
浏览 24
已采纳

PHP调试:结合foreach和exit

While debugging, it would help if I could exit() and use a foreach to print individual elements of an array. Any ideas?

  • 写回答

5条回答 默认 最新

  • dongxiao0449 2011-02-26 01:10
    关注

    If you want to easily print the contents of an array or any other PHP value, use var_dump. Calling exit() is orthogonal to this, and I think it's quite clear to write:

    var_dump($arr);
    exit(1);
    

    Another technique is to log your output, which is potentially more useful if you don't want to sift through your output HTML to look for the output of var_dump:

    error_log(var_export($arr));
    exit(1);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?