数组显示实用程序,用于人可读和PHP代码插入
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数组显示实用程序,用于人可读和PHP代码插入相关的知识,希望对你有一定的参考价值。
# function *formatArrayForDisplay*## parameters:
* **array**
a 1- or 2-dimensional array for output
* **mode**
accepts **human** or **php**
* **human** displays using `<pre>` tags and print_r
* **PHP** displays PHP style formatting for creating the same array using a PHP script, useful for unit tests when source data is needed.
## returns:
* **void**, all output is directed through **echo**
function formatArrayForDisplay($array,$mode='human'){ switch($mode){ case 'human': // outputs array as human-readable: break; case 'PHP': // outputs array as PHP-ready string: echo "array("; $comma = ''; foreach($array as $key=>$value){ echo "$comma "; echo "array("; $comma2 = ''; foreach($value as $key2=>$value2){ echo "$comma2 '$key2'=>'$value2'"; $comma2 = ','; }; echo ")"; }else{ echo "'$value'"; } $comma = ','; }; echo ");"; break; } }
以上是关于数组显示实用程序,用于人可读和PHP代码插入的主要内容,如果未能解决你的问题,请参考以下文章