#_POST key/value question. [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
spedula
Forum Commoner
Posts: 81
Joined: Mon Mar 29, 2010 5:24 pm

#_POST key/value question. [SOLVED]

Post by spedula »

Is there a way to access $_POST values without knowing the key?

For Example:

Code: Select all


for ($i = 0; $i < count($_POST); $i++) {
   echo $_POST[$i].'<br>';
}

I managed to find something that kind of works but if the post value itself is an array, it just saves it as a string, "Array", and not the values inside that array. I need to be able to preserve the value if it's an array as well.

Code: Select all



if ($_POST) {
  $postKeys = array();
  $postVals = array();
  foreach ($_POST as $k => $v) {
    $postKeys[] = "$k";
    $postVals[] = "$v";
  }
}

Last edited by spedula on Sun Jan 02, 2011 11:28 pm, edited 1 time in total.
User avatar
spedula
Forum Commoner
Posts: 81
Joined: Mon Mar 29, 2010 5:24 pm

Re: #_POST key/value question.

Post by spedula »

Found the answer myself.

Code: Select all


$form_values = array_values($_POST);

That will store all the $_POST associated array values as numerical array values.
Post Reply