<?php

function print_array($array, $levelsOpen = null, $identifier = 0, $level = 0, &$i = 0)
{
    if (!is_array($array))
    {
        return false;
    }

    $success = false;

    while (!$success)
    {
        if (!defined('PRINT_ARRAY_' . $identifier) || $level)
        {
            $success = true;
            define('PRINT_ARRAY_' . $identifier, true);
        }
        else
        {
            $identifier ++;
        }
    }

    if (!defined('PRINT_ARRAY_USED'))
    {
        echo '<style type="text/css">.arrayOutputBlock{font-family:"Courier New","Courier",monospace;font-size:12px}.arrayOutputChildBlock{padding-left: 35px}.arrayOutputBlock a{color:red;text-decoration:none}.arrayOutputBlock a:hover{text-decoration:underline}</style><script type="text/javascript">function toggleArrayOutputBlock(i){var top=document.getElementById("arrayOutputChildBlockTop"+i);var block=document.getElementById("arrayOutputChildBlock"+i);if(top.style.display=="none"){top.style.display="inline";block.style.display="none";}else{top.style.display="none";block.style.display="block";}return false;}function toggleHighlightArrayOutputBlock(i){var block=document.getElementById("arrayOutputChildBlock"+i);if(block.style.backgroundColor=="rgb(255, 255, 153)"||block.style.backgroundColor=="rgb(255,255,153)"){block.style.backgroundColor="";}else{block.style.backgroundColor="rgb(255, 255, 153)";}}</script>';
        define('PRINT_ARRAY_USED', true);
    }

    if (!$level)
    {
        echo '<div class="arrayOutputBlock"><a href="#" onclick="return toggleArrayOutputBlock(\'' . $identifier . 'z' . $i . '\');" onmouseover="toggleHighlightArrayOutputBlock(\'' . $identifier . 'z' . $i . '\');" onmouseout="toggleHighlightArrayOutputBlock(\'' . $identifier . 'z' . $i . '\');"><em>Array</em></a> <span id="arrayOutputChildBlockTop' . $identifier . 'z' . $i . '"' . (($levelsOpen !== null && $level + 1 > $levelsOpen) ? '' : ' style="display: none;"') . '>(' . count($array) . ' childs)</span><div class="arrayOutputChildBlock" id="arrayOutputChildBlock' . $identifier . 'z' . $i . '"' . (($levelsOpen !== null && $level + 1 > $levelsOpen) ? ' style="display: none;"' : '') . '>';
        print_array($array, $levelsOpen, $identifier, $level + 1, $i);
        echo '</div></div>';
    }
    else
    {
        foreach ($array as $key => $value)
        {
            if (is_array($value))
            {
                $i ++;
                echo '[' . htmlentities($key, ENT_QUOTES) . '] =&gt; <a href="#" onclick="return toggleArrayOutputBlock(\'' . $identifier . 'z' . $i . '\');" onmouseover="toggleHighlightArrayOutputBlock(\'' . $identifier . 'z' . $i . '\');" onmouseout="toggleHighlightArrayOutputBlock(\'' . $identifier . 'z' . $i . '\');"><em>Array</em></a> <span id="arrayOutputChildBlockTop' . $identifier . 'z' . $i . '"' . (($levelsOpen !== null && $level + 1 > $levelsOpen) ? '' : ' style="display: none;"') . '>(' . count($value) . ' childs)<br /></span><div class="arrayOutputChildBlock" id="arrayOutputChildBlock' . $identifier . 'z' . $i . '"' . (($levelsOpen !== null && $level + 1 > $levelsOpen) ? ' style="display: none;"' : '') . '>';
                print_array($value, $levelsOpen, $identifier, $level + 1, $i);
                echo '</div>';
            }
            elseif (is_object($value))
            {
                $vars = get_object_vars($value);
                $i ++;
                echo '[' . htmlentities($key, ENT_QUOTES) . '] =&gt; <a href="#" onclick="return toggleArrayOutputBlock(\'' . $identifier . 'z' . $i . '\');" onmouseover="toggleHighlightArrayOutputBlock(\'' . $identifier . 'z' . $i . '\');" onmouseout="toggleHighlightArrayOutputBlock(\'' . $identifier . 'z' . $i . '\');"><em>' . htmlentities(get_class($value), ENT_QUOTES) . ' Object</em></a> <span id="arrayOutputChildBlockTop' . $identifier . 'z' . $i . '"' . (($levelsOpen !== null && $level + 1 > $levelsOpen) ? '' : ' style="display: none;"') . '>(' . count($vars) . ' childs)<br /></span><div class="arrayOutputChildBlock" id="arrayOutputChildBlock' . $identifier . 'z' . $i . '"' . (($levelsOpen !== null && $level + 1 > $levelsOpen) ? ' style="display: none;"' : '') . '>';
                print_array($vars, $levelsOpen, $identifier, $level + 1, $i);
                echo '</div>';
            }
            elseif (is_bool($value))
            {
                echo '[' . htmlentities($key, ENT_QUOTES) . '] =&gt; <em>' . (($value) ? 'true' : 'false') . '</em><br />';
            }
            elseif (is_null($value))
            {
                echo '[' . htmlentities($key, ENT_QUOTES) . '] =&gt; <em>null</em><br />';
            }
            else
            {
                echo '[' . htmlentities($key, ENT_QUOTES) . '] =&gt; ' . htmlentities($value, ENT_QUOTES) . '<br />';
            }
        }
    }

    return true;
}

?>

[b]Gebruik:[/b]
<?php

class lol
{
    var $name = 'lol';
}

$array = array(
    true,
    1,
    1.7,
    'lol',
    array_fill(0, 3, 'lol'),
    new lol,
    null
);

print_array($array);

?>