php 调试值辅助函数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 调试值辅助函数相关的知识,希望对你有一定的参考价值。
<span style="color: #000000; font-weight: bold;">function</span> dval<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$val</span>, <span style="color: #0000ff;">$print</span>=<span style="color: #000000; font-weight: bold;">true</span>, <span style="color: #0000ff;">$method</span>=<span style="color: #ff0000;">'var_export'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #808080; font-style: italic;">// dval = Debug a VALue -> easy to remember for me</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$method</span> == <span style="color: #ff0000;">'var_export'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #0000ff;">$r</span> = <a href="http://www.php.net/var_export"><span style="color: #000066;">var_export</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$val</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">)</span>;
<span style="color: #66cc66;">}</span>
<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span>
<span style="color: #0000ff;">$r</span> = <a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$val</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">)</span>;
<span style="color: #66cc66;">}</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$print</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span> <a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">"<pre>[["</span> . <a href="http://www.php.net/htmlspecialchars"><span style="color: #000066;">htmlspecialchars</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$r</span><span style="color: #66cc66;">)</span> . <span style="color: #ff0000;">"]]</pre>"</span>; <span style="color: #66cc66;">}</span>
<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span> <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">"<pre>[["</span> . <a href="http://www.php.net/htmlspecialchars"><span style="color: #000066;">htmlspecialchars</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$r</span><span style="color: #66cc66;">)</span> . <span style="color: #ff0000;">"]]</pre>"</span>; <span style="color: #66cc66;">}</span>
<span style="color: #66cc66;">}</span>
以上是关于php 调试值辅助函数的主要内容,如果未能解决你的问题,请参考以下文章