It is also worth mentioning that you can pass true as the second parameter to print_r to get the data as string.

Featured on Meta @Elias I updated the script above, can't quite remember why I was replacing the spaces. We use cookies to ensure you have the best browsing experience on our website.

Remember to always htmlspecialchars print_r output, if it can contain html characters. An expert in iOS software design and development, she specializes in building technical hybrid platforms. Let's say, for example, we create the following array in PHP. The Overflow Blog

I was having problems using print_r because I didn't like the fact that if tags where included in the array it would still be parsed by the browsers. Stack Overflow works best with JavaScript enabled Now you can return '

'.print_r(User::all(), true); from your … This handles nested arrays without issue as far as I can tell. Filed Under: PHP Arrays Tagged With: access elements, adding elements, array_values, change elements, deleting elements, php arrays, print_r, read array values, removing elements, unset. To answer your question: No, there is no built-in function to parse the output of print_r into an array again. This works around the hacky nature of print_r in return mode (using output buffering for the return mode to work is hacky...): This tutorial tackles on how to beautifully display PHP array. $_POST is an array in itsself you don't need to make an array out of it. Free 30 Day Trial                                            
 my take on the highlighted markupped debug function:
 It is easy to set up page redirects using PHP and if you are wondering how often your visitors check out your website, use PHP to set up a counter. Usage: 

ThoughtCo uses cookies to provide you with a great user experience. By using ThoughtCo, you accept our He used

 for it to work, but that might not be always the best method to go. We had an interesting problem dumping an object that If your class has an toArray function, that one will be called otherwise it will return the object as is.  "\n\n" The tag  Another attempt that tries to overcome the memory blowout when the passed in data has mutual recursion. 

your coworkers to find and share information. print_r is used for debug purposes. This tutorial will provide you a simple solution on how to prettify your PHP array display.

The print_r() function is a built-in function in PHP and is used to print or display information stored in a variable.If you like GeeksforGeeks and would like to contribute, you can also write an article using Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.Please write to us at contribute@geeksforgeeks.org to report any issue with the above content. What you did is nest the $_POST array inside a new array.

liamtoh6@hotmail.com posted a function that will echo print_r output with proper new lines in HTML files.

I add this function to the global scope on just about every project I do, it makes reading the output of print_r() in a browser infinitely easier.

// this is a tested array/recursive call to this function // make sure we only match stuff with 4 preceding spaces (stuff for this array and not a nested one) // recursively see if the parsed out value is an array too

This is not a bug; sensitive information (ex.

In this article, we will go over the PHP print_r() function. Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML. In manipulating array with PHP, often times we use print_r() or var_dump() function to display data in an array but the presentation of data in this functions is not usually eye-friendly for developers. '\" style=\"display: none;\">'"// replace ')' on its own on a new line (surrounded by whitespace is ok) with '

// print the javascript function toggleDisplay() and then the transformed output'