Created
January 23, 2019 06:49
-
-
Save wczmatthew/f5dc30ca4d6b0811ff4a612f85ce0200 to your computer and use it in GitHub Desktop.
输出数组信息
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dump($var, $echo=true, $label=null, $strict=true) { | |
$label = ($label === null) ? '' : rtrim($label) . ' '; | |
if (!$strict) { | |
if (ini_get('html_errors')) { | |
$output = print_r($var, true); | |
$output = "<pre>" . $label . htmlspecialchars($output, ENT_QUOTES) . "</pre>"; | |
} else { | |
$output = $label . print_r($var, true); | |
} | |
} else { | |
ob_start(); | |
var_dump($var); | |
$output = ob_get_clean(); | |
if (!extension_loaded('xdebug')) { | |
$output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output); | |
$output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>'; | |
} | |
} | |
if ($echo) { | |
echo($output); | |
return null; | |
}else | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment