Dies ist eine alte Version des Dokuments!


Variableninhalt anzeigen (PHP)

<?php
function my_var_dump ($var, $depth = 1)
{
    if (is_array($var))
    {
        $indentation = str_repeat(' ', 3 * $depth);
        echo "array(\n";
        foreach ($var as $key => $value)
        {
            echo str_repeat(' ', 3 * $depth), htmlspecialchars($key), " => ";
            my_var_dump($value, $depth + 1);
        }
        echo str_repeat(' ', 3 * ($depth - 1)), ")\n";
    }
    else
    {
        $type = gettype($var);
        switch ($type)
        {
            case 'resource':
            case 'object':
                echo $type, "\n";
                break;
            case 'NULL':
                echo "NULL\n";
                break;
            case 'string':
                if (strlen($var) > 40)
                    $var = substr($var, 0, 40). '...';
                echo $type, "(\"", htmlspecialchars($var), "\")\n";
                break;
            default:
                echo $type, "(", $var, ")\n";
        }
    }
}