www.webdeveloper.com
Results 1 to 2 of 2

Thread: receiving associative arrays with $_post

  1. #1
    Join Date
    Sep 2006
    Posts
    58

    Question receiving associative arrays with $_post

    Hi guys,

    Sorry if this a noob question.

    I would like to know how receiving an associative array with $_post

    A normal variable can be declared like so

    ie $myvar = $_POST['myvar'];

    But what about a variable in an associative array.

    ie $id['myvar'] = $_POST["id['myvar']"]; //is this legal code?

    this does not seem right as $_POST is already an array.

    thanks for any enlightenment.

  2. #2
    Join Date
    Mar 2004
    Posts
    369
    You can POST an numerically-indexed array to a script like this
    Code:
    <form action="myscript.php">
      <input type="text" name="myVar[0]">
      <input type="text" name="myVar[1]">
      <input type="text" name="myVar[2]">
    </form>
    You can also leave out the numbers and this will accomplish the exact same thing...
    Code:
    <form action="myscript.php">
      <input type="text" name="myVar[]">
      <input type="text" name="myVar[]">
      <input type="text" name="myVar[]">
    </form>
    You can access the array in PHP using $_POST['myVar'][0], etc.

    You can POST an associative array to a script like this
    Code:
    <form action="myscript.php">
      <input type="text" name="myVar[tom]">
      <input type="text" name="myVar[dick]">
      <input type="text" name="myVar[harry]">
    </form>
    You can access the array in PHP using $_POST['myVar']['tom'], etc.

    Hope that helps.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles