tags:

views:

250

answers:

8

Maybe the code looks like something like this:

foreach(...$POST){
echo $key."<br/>;
}
+3  A: 

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/>";
}
Sean Vieira
+10  A: 
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.

erenon
This is the best way to do it, use some `<pre>...</pre>` tags around it for better formatting.
Jakub
Additionally, if he only wants the keys, `array_keys()` will do it.
Pascal
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.
Richy C.
A: 

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

ApoY2k
+1  A: 

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);
cletus
A: 
$array = array_flip($array);
echo implode('any glue between array keys',$array);
Ben Werdmuller
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.
Ben Werdmuller
A: 

Or you could just print out the array keys:

foreach (array_keys($_POST) as $key) {
    echo "$key<br/>\n";
}
jonstjohn
`"$key"`... sorry...
ApoY2k
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.
jonstjohn
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...
ApoY2k
which part is bad style?
jonstjohn
Well, not to escape variables is bad style IMHO. No matter what kind of variables, they should always be escaped.
ApoY2k
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.
jonstjohn
+3  A: 

Tested one liner:

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

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

Chris