3

Maybe the code looks like something like this:

foreach(...$POST){ echo $key."<br/>; } 
2
  • 1
    This question has been asked numerous times before. Commented Nov 16, 2009 at 15:22
  • like here: stackoverflow.com/questions/693637/… Commented Nov 16, 2009 at 15:30

8 Answers 8

11
var_dump($_POST); 

or

print_r($_POST); 

You might insert a pre tag before and after for the clearer output in your browser:

echo '<pre>'; var_dump($_POST); echo '</pre>'; 

And I suggest to use Xdebug. It provides an enchanted var_dump that works without pre's as well.

Sign up to request clarification or add additional context in comments.

3 Comments

This is the best way to do it, use some <pre>...</pre> tags around it for better formatting.
Additionally, if he only wants the keys, array_keys() will do it.
You could also do print nl2br(print_r($_POST)); (replace $_POST with the name of your array) to avoid having to bother with the pre tags.
3

See the PHP documentation on foreach: http://php.net/manual/en/control-structures.foreach.php

Your code would look something like this:

foreach ($_POST as $key=>$element) { echo $key."<br/>"; } 

Comments

3

Tested one liner:

echo join('<br />',array_keys($_POST)); 

Comments

1

If you want to do something with them programmatically (eg turn them into a list or table), just loop:

foreach ($_POST as $k => $v) { echo $k . "<br>"; } 

For debugging purposes:

print_r($_POST); 

or

var_dump($_POST); 

Comments

0

And if you want full coverage of the whole array, print_r or even more detailed var_dump

Comments

0
$array = array_flip($array); echo implode('any glue between array keys',$array); 

1 Comment

NB: I'm assuming you don't just want to do this for debug purposes. Otherwise print_r, var_dump, var_export etc are good choices.
0

Or you could just print out the array keys:

foreach (array_keys($_POST) as $key) { echo "$key<br/>\n"; } 

4 Comments

This answers the question exactly but received a down-vote. Down-voter care to add a comment? Obviously, the '<br/>\n' could be dropped but was provided for formatting.
I didn't want my comment to be a reason for other people to downvote that... it's just bad PHP-style thats all. No reason to downing...
Well, not to escape variables is bad style IMHO. No matter what kind of variables, they should always be escaped.
Wow, your response makes no sense. Escaping the contents of a variable for inserting into SQL (from a post) to prevent SQL injection makes sense, and there are other reasons that you would want to escape a variable. But just for examining the contents of an array, it is entirely unnecessary.
0

Normally I would use print_r($_POST).

If using within an HTML page, it's probably worth wrapping in a <pre> tag to get a better looking output, otherwise the useful tabs and line breaks only appear in source view.

print_r() on PHP.net

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.