Skip to content
Advertisement

Formatting print_r or var_dump results

I would like new lines and indents shown in this output

JavaScript

So instead of this:

JavaScript

I would get something like this:

JavaScript

Advertisement

Answer

I suggest using HTML’s <pre> tag (preformatting):

JavaScript

EDIT:

To concatenate the output, you must set the second parameter of print_r to true to return the value rather than echoing it:

JavaScript

print_r ( mixed $value , bool $return = false ) : string|bool
If you would like to capture the output of print_r(), use the return parameter. When this parameter is set to true, print_r() will return the information rather than print it.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement