When I echo var_dump($_variable), I get one long, wrapping line with all varable\'s and values like
[\"kt_login_user\"]=> string(8) \"teacher1\" [\"kt_lo
var_export will give you a nice output. Examples from the docs:
$a = array (1, 2, array ("a", "b", "c"));
echo '<pre>' . var_export($a, true) . '</pre>';
Will output:
array (
0 => 1,
1 => 2,
2 =>
array (
0 => 'a',
1 => 'b',
2 => 'c',
),
)
I did a similar solution. I've created a snippet to replace 'vardump' with this:
foreach ($variable as $key => $reg) {
echo "<pre>{$key} => '{$reg}'</pre>";
}
var_dump($variable);die;
Ps: I'm repeating the data with the last var_dump to get the filename and line
So this: Became this:
Let me know if this will help you.
Personally I like the replacement function provided by Symfony's var dumper component
Install with composer require symfony/var-dumper
and just use dump($var)
It takes care of the rest. I believe there's also a bit of JS injected there to allow you to interact with the output a bit.
Wrap it in <pre>
tags to preserve formatting.
I really love var_export(). If you like copy/paste-able code, try:
echo '<pre>' . var_export($data, true) . '</pre>';
Or even something like this for color syntax highlighting:
highlight_string("<?php\n\$data =\n" . var_export($data, true) . ";\n?>");
For devs needing something that works in the view source and the CLI, especially useful when debugging unit tests.
echo vd([['foo'=>1, 'bar'=>2]]);
function vd($in) {
ob_start();
var_dump($in);
return "\n" . preg_replace("/=>[\r\n\s]+/", "=> ", ob_get_clean());
}
Yields:
array(1) {
[0] => array(2) {
'foo' => int(1)
'bar' => int(2)
}
}