Zend - The PHP Company




Arrays

Add Code


aprint()  

Type: code fragment
Added by: _roy
Entered: 22/07/2005
Last modified: 01/11/2006
Rating: - (fewer than 3 votes)
Views: 2896
similar to print_r(), beside highlighting and syntax - that allows you simply copy and paste printed array into your php code.


<?php

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) == )
        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$colonn";
    }
    
    if( 
$tab == )
    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 
"nn<table style="width:100%; margin:1pxbackground:#F0F2F4; border:1px solid #D8DDE6;"><tbody><tr><td><pre style="color:#000000;">$prefix"._aprint($arr)."</pre></td></tr></tbody></table>nn";
    // overflow:auto;
}

?>


Usage Example


aprint( $myarray );


Rate This Script





Search



This Category All Categories