PHP: Get print_r Into A Variable

print_r is a great php function that dumps all of the contents within an array in a neat format, no matter how deeply nested your arrays are.

Someone today asked me, “How do you include the output of print_r() within a variable?”. So I thought I would write a short post on how it’s done!

You simply set the return flag like this:

$variable = print_r($array, true);

$variable now contains the output of print_r(). And that’s it!

Free Graphics, Icons, Tutorials
Free Graphics Free Christmas Vector Icon Graphics Pack 2017Free Fitness Vector Icons Graphics PackFree Camping Vector Graphics PackFree Summer Graphics PackFree File Icon PackFree Fast Food Vector Graphics
Sharing is caring...
Like & Follow
Share the love, share this page! Facebook Twitter Google Digg Reddit LinkedIn Pinterest Email
Close [X]
The Web Taylor
1000 Lakeside North Harbour Portsmouth, Hampshire PO6 3EN
02392 123358