Greetings.

I want to add some key => value pairs that will come from a web form to an array, but can't figure out how to do it.

In code terms, I'd like to do something like the following:

$myArray = array();

foreach ($_POST as $k => $v)
{
    array_push($myArray, $k => $v);
}

Please can someone help me?

Thanks in advance,

    $myArray = array();
    
    foreach ($_POST as $k => $v)
    {
    	$myArray[$k] = $v;
    }

    though frankly you're better off using $_POST directly.

          $myArray = array();
      
      foreach ($_POST as $k => $v)
      {
          array_push($myArray, $k => $v);
      }
      
      ## Couldn't this be done simply by saying
      $myArray = $_POST;

        Damn, thank you all for the quick reply.

        I've should figured this. Guess I'm working too much to be able to think straight.

        Thanks a lot, folks!

          Ah, but now that you've cleared this up, you might want to consider reasons for using $_POST directly.

          This would include the fact that $_POST is superglobal, while your new array will not be global.

          If you do perform validation of incoming variables (which you should), then you'll probably have to hardcode the checks.
          This means that automatically transferring the elements of $_POST to another function probably isnt satisfactory, or is at least a waste of time.

            Write a Reply...