I\'m building a PHP script that feeds JSON data to another script. My script builds data into a large associative array, and then outputs the data using json_encode
print_r pretty print for PHP
Example PHP
function print_nice($elem,$max_level=10,$print_nice_stack=array()){
if(is_array($elem) || is_object($elem)){
if(in_array($elem,$print_nice_stack,true)){
echo "RECURSION";
return;
}
$print_nice_stack[]=&$elem;
if($max_level<1){
echo "nivel maximo alcanzado";
return;
}
$max_level--;
echo "";
if(is_array($elem)){
echo 'ARRAY ';
}else{
echo '';
echo 'OBJECT Type: '.get_class($elem).' ';
}
$color=0;
foreach($elem as $k => $v){
if($max_level%2){
$rgb=($color++%2)?"#888888":"#BBBBBB";
}else{
$rgb=($color++%2)?"#8888BB":"#BBBBFF";
}
echo '';
echo ''.$k." ";
print_nice($v,$max_level,$print_nice_stack);
echo " ";
}
echo "
";
return;
}
if($elem === null){
echo "NULL";
}elseif($elem === 0){
echo "0";
}elseif($elem === true){
echo "TRUE";
}elseif($elem === false){
echo "FALSE";
}elseif($elem === ""){
echo "EMPTY STRING";
}else{
echo str_replace("\n","*
\n",$elem);
}
}