Created
May 24, 2013 18:15
-
-
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).
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
<?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