/ Published in: 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.
- human displays using
- void, all output is directed through echo
Expand |
Embed | Plain Text
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; } }
You need to login to post a comment.
