Algorithms - aprint() - php code
04 February 2009 01:13 | osi | 0 fav | 0 comment
| Tags:
algorithms
,
array
,
php
,
php scripts
,
php code
,
php codes
,
php examples
,
php help
,
php snippets
,
php tutorials
function _aprint($arr, $tab = 1) // similar to print_r()
{
if( !is_array($arr) ) return " <span style=\"color:#336699\">".ucfirst(gettype($arr))."</span> "._slashes($arr);
$space = str_repeat("\t", $tab);
$out = " <span style=\"color:#336699\">array(</span>\n";
end($arr); $end = key($arr);
if( count($arr) == 0 )
return "<span style=\"color:#336699\">array()</span>";
foreach( $arr as $key=>$val ){
if( $key == $end ) $colon = ''; else $colon = ',';
if( !is_numeric($key) ) $key = "<span style=\"color:#993366\">'".str_replace( array("\\","'"), array("\\\\","\'"), htmlspecialchars($key) )."'</span>";
if( is_array($val) ) $val = _aprint($val, ($tab+1)); else
if( !is_numeric($val) ) $val = "<span style=\"color:#993366\">'".str_replace( array("\\","'"), array("\\\\","\'"), htmlspecialchars($val) )."'</span>";
$out .= "$space$key => $val$colon\n";
}
if( $tab == 1 )
return "$out$space<span style=\"color:#336699\"> )</span>;"; else
return "$out$space<span style=\"color:#336699\"> )</span>";
}
function aprint( $arr, $prefix=''){
if( ltrim($prefix) != '' ) $prefix = '<span style="color:#336699">'.$prefix.'</span> =';
echo "\n\n<table style=\"width:100%; margin:1px; background:#F0F2F4; border:1px solid #D8DDE6;\"><tbody><tr><td><pre style=\"color:#000000;\">$prefix"._aprint($arr)."</pre></td></tr></tbody></table>\n\n";
// overflow:auto;
}
