Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    Accessing a form array in key=>value form

    okay, I have a form with many inputs like the following:

    Code:
    <input type="text" name="sortorder[29]" size="1" class="admin_sortorder" value="0" />
    <input type="text" name="sortorder[23]" size="1" class="admin_sortorder" value="0" />
    <input type="text" name="sortorder[34]" size="1" class="admin_sortorder" value="0" />
    <input type="text" name="sortorder[25]" size="1" class="admin_sortorder" value="0" />
    I want to be able to access them in key=>value form. For example, i was pondering the following code:

    PHP Code:
    for($_POST['sortorder'] as $key=>$value)
    {
    //execute w/e here.

    How do I do something like that?

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Change for to foreach and it should work. You would use the $key & $value variables inside of the brackets however you wanted.

  • #3
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    PHP Code:
    foreach ($_POST['sortorder'] as $key=>$value)
    {
    //execute w/e here.



    that should solve your problem

  • #4
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    thx. I guess I was thinking on the right lines then.

  • #5
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    you sure were mate, you sure were...


  •  

    Posting Permissions

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