I have a form that has multiple fields, and for testing purposes is there a way I could print out the values entered in all the fields, without having to individually print each value.
11 Answers
You should be able to do a var_dump($_REQUEST);

- 1,064
- 11
- 13
-
While this really answers the question very well, and works perfectly, I am wondering if having a var_dump of **user provided** data can be a security risk (if the php-doc that contains the var_dump) would be reachable from a untrusted source? Do you know if your suggested solution is also safe? – humanityANDpeace Oct 06 '13 at 08:00
-
2@humanityANDpeace you shouldn't be using var_dump in a production environment, its really just for testing purposes. So the only user who could provide unsafe data should be you :) – Ted Avery Nov 13 '13 at 12:04
For extra credit, I always have:
function pre($data) {
print '<pre>' . print_r($data, true) . '</pre>';
}
Whenever I need to debug an array - which is very often - I just do pre($arr); to get a nicely formatted dump.

- 480,997
- 81
- 517
- 436
print_r()
/ var_dump()
are simple and gets the job done.
If you want a styled/dynamic option check out Krumo:
A lot of developers use
print_r()
andvar_dump()
... Krumo is an alternative: it does the same job, but it presents the information beautified using CSS and DHTML.

- 1
- 1

- 12,356
- 2
- 32
- 37
I basically use:
echo "<pre>"; print_r($_POST) ; echo "</pre>";
It prints the post values in a nice formatted way.

- 30,738
- 21
- 105
- 131

- 2,139
- 1
- 27
- 44
If you pay close attention to the $_POST[]
or $_GET[]
method, you will realize that both of them are actually arrays.This means that you can play around with them just like you do with any other arrays.
For example, you can print_r($_POST)
and you will see everything the way were entered..
This PHP code doesn't require any knowledge of the fields in the form that submits to it, it just loops through all of the fields, including multiple-choice fields (like checkboxes), and spits out their values.
<?php
// loop through every form field
while( list( $field, $value ) = each( $_POST )) {
// display values
if( is_array( $value )) {
// if checkbox (or other multiple value fields)
while( list( $arrayField, $arrayValue ) = each( $value ) {
echo "<p>" . $arrayValue . "</p>\n";
}
} else {
echo "<p>" . $value . "</p>\n";
}
}
?>

- 813
- 5
- 14
This shows more than just POST variables, but it's about as easy as it gets.
<?php
phpinfo(INFO_VARIABLES);
?>

- 349
- 3
- 4
Besides using inline debug statements, you could also considering transient debugging, i.e. you could use an IDE with debug capabilities, like eclipse or zend studio. This way you could watch any variable you'd like to.
bye!

- 39
- 1
use print_r($_POST);
or var_dump($_POST);
you can always display var echo command:
echo ($_POST['value']);

- 19
- 6
Very simply,
phpinfo();
It includes a listing of all variables passed to PHP from a form, in an easy-to-read format.

- 30,738
- 21
- 105
- 131