Exemplo n.º 1
0
function output($data, array $settings = [], bool $content = false)
{
    // ---------------------------------------------------------------------------------------------
    // AYARLAR
    // ---------------------------------------------------------------------------------------------
    $textType = $settings['textType'] ?? 'monospace, Tahoma, Arial';
    $textSize = $settings['textSize'] ?? '12px';
    // ---------------------------------------------------------------------------------------------
    $globalStyle = ' style="font-family:' . $textType . '; font-size:' . $textSize . ';"';
    $output = "<span{$globalStyle}>";
    $output .= internalOutput($data, '', 0, $settings);
    $output .= "</span>";
    if ($content === false) {
        echo $output;
    } else {
        return $output;
    }
}
Exemplo n.º 2
0
function internalOutput($data, string $tab = '', int $start = 0, array $settings = []) : string
{
    static $start;
    $lengthColor = $settings['lengthColor'] ?? 'grey';
    $keyColor = $settings['keyColor'] ?? '#000';
    $typeColor = $settings['typeColor'] ?? '#8C2300';
    $stringColor = $settings['stringColor'] ?? 'red';
    $numericColor = $settings['numericColor'] ?? 'green';
    $output = '';
    $eof = '<br>';
    $tab = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', $start);
    $lengthstyle = ' style="color:' . $lengthColor . '"';
    $keystyle = ' style="color:' . $keyColor . '"';
    $typestyle = ' style="color:' . $typeColor . '"';
    $vartype = 'array';
    if (is_object($data)) {
        $data = (array) $data;
        $vartype = 'object';
    }
    if (!is_array($data)) {
        return $data . $eof;
    } else {
        foreach ($data as $k => $v) {
            if (is_object($v)) {
                $v = (array) $v;
                $vartype = 'object';
            }
            if (!is_array($v)) {
                $valstyle = ' style="color:' . $numericColor . ';"';
                $type = gettype($v);
                if ($type === 'string') {
                    $v = "'" . $v . "'";
                    $valstyle = ' style="color:' . $stringColor . ';"';
                    $type = 'string';
                } elseif ($type === 'boolean') {
                    $v = $v === true ? 'true' : 'false';
                    $type = 'boolean';
                }
                $output .= "{$tab}<span{$keystyle}>{$k}</span> => <span{$typestyle}>{$type}</span> <span{$valstyle}>{$v}</span> <span{$lengthstyle}>( length = " . strlen($v) . " )</span>,{$eof}";
            } else {
                $output .= "{$tab}<span{$keystyle}>{$k}</span> => <span{$typestyle}>{$vartype}</span> {$eof} {$tab}( {$eof} " . internalOutput($v, $tab, (int) $start++) . " {$tab}), " . $eof;
                $start--;
            }
        }
    }
    return $output;
}