Making PHP var_dump() values display one line per value
I usually have a nice function to handle output of an array, just to pretty it up a bit when debugging.
function pr($data){ echo "<pre>"; print_r($data); // or var_dump($data); echo "</pre>";}
Then just call it
pr($array);
Or if you have an editor like that saves snippets so you can access them quicker instead of creating a function for each project you build or each page that requires just a quick test.
For print_r
:
echo "<pre>", print_r($data, 1), "</pre>";
For var_dump()
:
echo "<pre>", var_dump($data), "</pre>";
I use the above with PHP Storm. I have set it as a pr
tab command.
I've also researched this issue and not found the right answer. This doesn't work for me:
echo '<pre>' . var_dump($variable) . '</pre>';
This will not provide a nice display of the array for me, with line breaks (I'm using Firefox 31.3.0)
However, after some experimentation, this solved the problem (notice the php is closed at first):
... ?> <pre><?php echo var_dump($variable) ?></pre> <?php ...
This solves the problem and displays a nice, easy-to-read array for me on my browser. You see how the tags are not wrapped in PHP; only the echo var_dump part is.