Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dump_helper: functions to dump variables to the screen, in a nicley formatted manner
<?php
/**
* Dump helper. Functions to dump variables to the screen, in a nicley formatted manner.
* @author Joost van Veen
* @version 1.0
*/
if (!function_exists('dump')) {
function dump ($var, $label = 'Dump', $echo = TRUE)
{
// Store dump in variable
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 dotted #000; padding: 10px; margin: 10px 0; text-align: left;">' . $label . ' => ' . $output . '</pre>';
// Output
if ($echo == TRUE) {
echo $output;
}
else {
return $output;
}
}
}
if (!function_exists('dump_exit')) {
function dump_exit($var, $label = 'Dump', $echo = TRUE) {
dump ($var, $label, $echo);
exit;
}
}
@umagrama

This comment has been minimized.

Copy link

umagrama commented Nov 22, 2013

Love this little helper... thanks!

@mabena

This comment has been minimized.

Copy link

mabena commented May 13, 2015

Nice peace of code... Thanks!

@vnvkalyankrishna

This comment has been minimized.

Copy link

vnvkalyankrishna commented Jun 7, 2015

Thankyou......

@thilina570

This comment has been minimized.

Copy link

thilina570 commented Jul 9, 2015

good works

@spreaderman

This comment has been minimized.

Copy link

spreaderman commented Nov 4, 2015

Very nice

@fearrr

This comment has been minimized.

Copy link

fearrr commented Dec 14, 2016

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.