<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
 * a function to view your array in detail. you don't need to worry about $space. it's for the layout.
 *
 * @license      http://www.gnu.org/licenses/gpl.html
 * @author       stijn1989 <stijnleenknegt@gmail.com>
 * @version      Versie 1.0
 * @package      PHP
 */

// full error reporting
error_reporting(E_ALL);

/**
 * this is a function that gives you big details of your array
 *
 * @param array $array
 * @param integer $space
 * @return void
 */
function array_dump( $array , $space = 0 )
{

    if( is_array( $array ) === false ) {
        die('You must give an array type as parameter for this function!');
    }

    //show the branch
    if( $space != 0 ) {
        echo "<img src=\"images/tree_1.gif\">";
        for( $i = 0 ; $i < $space ; $i++ ) {
            echo "<img src=\"images/tree_4.gif\">";
        }
    }
    echo "<img src=\"images/branch.png\">";
    echo " ";
    echo "<b>Array: </b>";
    echo count($array)." keys/values";
    echo "<br />";

    //show the leafs
    $c = 1;
    foreach($array as $k => $v) {
        
        if( is_array( $v ) === true ) {
            array_dump($v , $space + 1);
        } else {
            if( $space != 0 ) {
                echo "<img src=\"images/tree_3.gif\">";
                for( $i = 0 ; $i < $space ; $i++ ) {
                    echo "<img src=\"images/space.gif\">";
                }
            }
            echo ( count($array) == $c ) ? "<img src=\"images/tree_2.gif\">" : "<img src=\"images/tree_1.gif\">";
            echo "<img src=\"images/leaf.png\">";
            echo " ";
            echo "key: <b>" . $k . "</b>";
            echo " <b>-</b> ";
            echo "value: <b>" . $v . "</b>";
            echo " <b>-</b> ";
            echo "type: <b>" . gettype( $v ) ."</b>";
            echo "<br />";
        }
        $c++;

    }

}
?>