PHP调试:结合使用foreach和exit [英] PHP debugging: combine foreach and exit

查看:116
本文介绍了PHP调试:结合使用foreach和exit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试时,如果可以退出()并使用foreach来打印数组的单个元素,这将有所帮助。有任何想法吗?

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

推荐答案

如果要轻松打印数组的内容或任何其他PHP值,请使用 var_dump 。调用 exit()与此正交,我认为这样写很清楚:

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);

另一种方法是记录您的输出,如果您不想进行筛选,这可能会更有用通过您的输出HTML查找 var_dump 的输出:

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);

这篇关于PHP调试:结合使用foreach和exit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆