Skip to content

Instantly share code, notes, and snippets.

@ethaizone
Last active May 31, 2018 04:55
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 ethaizone/31788d00f09b22f47bb9d712ee4ea9b1 to your computer and use it in GitHub Desktop.
Save ethaizone/31788d00f09b22f47bb9d712ee4ea9b1 to your computer and use it in GitHub Desktop.
[PHP] Dump collection.
<?php
/**
* Dump collection. For who can't set breakpoint in their project.
*
* By EThaiZone
*/
if (! function_exists('jd')) {
/**
* Dump and json and exit
*/
function jd()
{
header('Content-Type: application/json');
echo json_encode(func_get_args());
exit;
}
}
if (! function_exists('d')) {
/**
* Dump as var_dump
*/
function d()
{
call_user_func_array('var_dump', func_get_args());
}
}
if (! function_exists('dd')) {
/**
* var_dump and exit
*/
function dd()
{
header('Content-Type: text/html');
call_user_func_array('d', func_get_args());
exit;
}
}
if (! function_exists('sd')) {
/**
* echo and exit
*/
function sd()
{
header('Content-Type: text/html');
foreach(func_get_args() as $v) {
if(is_string($v)) {
echo $v;
} elseif (is_array($v)) {
echo "<pre>".print_r((array) $v, true);
} else {
var_dump($v);
}
}
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment