Skip to content

Instantly share code, notes, and snippets.

@jsoningram
Created August 1, 2016 06:01
Show Gist options
  • Save jsoningram/51e8a097cb73be32fed124c7589d5af7 to your computer and use it in GitHub Desktop.
Save jsoningram/51e8a097cb73be32fed124c7589d5af7 to your computer and use it in GitHub Desktop.
Better print_r and more flexible var_dump
<?php
class View_Variables {
public static function dump( $variables, $die = true ) {
if ( is_array( $variables ) ) {
foreach ($variables as $var ) {
var_dump( $var );
}
} else {
var_dump( $variables );
}
if ( $die ) {
die();
}
}
public static function printr( $variables, $die = true ) {
echo '<pre>';
if ( is_array( $variables ) ) {
foreach ( $variables as $key => $val ) {
echo $key . ': ';
print_r( $val );
echo '<br>';
}
} else {
print_r( $variables );
}
echo '</pre>';
if ( $die ) {
die();
}
}
}
$view_variables = new View_Variables();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment