How to Print a Post Array in PHP
PHP uses an array variable called "$_POST" to hold all information posted by an HTML form to the server. If you set your HTML form to use the "post" method, then "$_POST" will hold the data submitted and allow you to grab it on another page in your website. The "print_r()" function provides an easy method for displaying the entire array when you want to print its contents while developing a form so you can see what data the server is reading.
Instructions
-
-
1
Open your PHP file in Notepad or a code editor. Locate the position in the code where you want to output the contents of the "$_POST" array.
-
2
Place the "$_POST" array inside the "print_r()" function:
print_r($_POST);
-
-
3
Add "<pre>" tags around the "print_r()" function to make the browser display the array contents in a readable format. Use "echo" statements to add the "<pre>" tags when writing them within any PHP code:
echo '<pre>';
print_r($_POST);
echo '</pre>';
-
4
Output the contents of "$_POST" using a "Foreach" loop if you want more control over how the information displays on the page. Set "$_POST" to a new variable to make it easier to work with when using this method:
$post_contents = $_POST;
foreach ($post_contents as $post_content) {
echo $post_content . '<br />';
}
-
1