Skip to content

Instantly share code, notes, and snippets.

@CrowderSoup
Created May 24, 2013 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CrowderSoup/5645445 to your computer and use it in GitHub Desktop.
Save CrowderSoup/5645445 to your computer and use it in GitHub Desktop.
A better better var_dump for arrays OR objects (or objects within arrays... or arrays within objects).
<?php
class util
{
/**
* SuperDump()
*
* Better var_dump for Arrays and Objects. Prints an array out in a
* formatted manner.
*
* @param $array array The array we want to print.
*/
public static function SuperDump($array)
{
echo "<ul>";
if(!empty($var)) {
if(is_numeric($var)) {
$type = gettype((int)$var);
} else {
$type = gettype($var);
}
if($type === "array" || $type === "object") {
foreach($var as $key => $val) {
if(is_array($val) || is_object($val)) {
echo "<li><strong>{$key}({$type})</strong>";
self::SuperDump($val);
echo "</li>";
} else {
if($type === "NULL") {
$val = "NULL";
}
echo "<li>{$key}({$type}): {$val}</li>";
}
}
} else {
echo "<li>{$type}: $var";
}
} else {
echo "<li>NULL: NULL</li>";
}
echo "</ul>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment