Variable Dump Helper

Submitted by kankuro - 9 years ago

Variable Dump Helper, a function to dump variables to the screen, in a nicely formatted manner. This is useful if you want to see the contents of your variable array. This is originally created by Mr. Joost van Veen. Source: https://gist.github.com/accent-interactive/3838495

/* Steps:
1. In your 'apps' directory create a folder called 'helpers'.
2. Within it create a PHP file. Example: 'AppsHelper.php'
3. Copy the code below and paste it then.
4. Open your composer.json file and add this one "app/helpers/" in the autoload classmap
5. Finally run composer dump-autoload in your command line.

How to:
$data = array('one', 'two', 'three');
AppsHelper::varDump($data);
*/
<?php

class AppsHelper {
    public static function varDump($var)
    {
        ob_start();
        var_dump($var);
        $output = ob_get_clean();

        // Add formatting
        $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);

        $output = '<pre style="background: #FFFEEF; color: #000; border: 1px dashed #888; padding: 10px; margin: 10px 0; text-align: left;">'.$output.'</pre>';

        echo $output;
    }
}