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 3 of 3
  1. #1
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts

    Some array help please

    So here is my question, hoefully I can get and answer.

    I have a form with fields like so, I'll use some basic values

    Code:
    <input type="text" name="C_0[]" value="entered 1" />
    <input type="text" name="C_0[]" value="entered 1" />
    <input type="text" name="C_0[]" value="entered 1" />
    <input type="text" name="C_1[]" value="entered 2" />
    <input type="text" name="C_1[]" value="entered 2" />
    <input type="text" name="C_1[]" value="entered 2" />
    <input type="text" name="C_2[]" value="entered 3" />
    <input type="text" name="C_2[]" value="entered 3" />
    <input type="text" name="C_2[]" value="entered 3" />
    Now I figured out how to get the POST data to show like so

    Code:
    entered 1, entered 1, entered 1
    entered 2, entered 2, entered 2
    entered 3, entered 3, entered 3
    Now my question is, how can i get the post data to show like so

    Code:
    entered 1, entered 2, entered 3
    entered 1, entered 2, entered 3
    entered 1, entered 2, entered 3
    im at a complete loss with this, google hasent helped me and Im not really sure what to be searching for in the first place.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    foreach ($_POST['C_0'] as $key => $val)
    {
        print($val.', '.$_POST['C_1'][$key].', '.$_POST['C_2'][$key]);
    }

  • Users who have thanked MattF for this post:

    seco (12-03-2010)

  • #3
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    Quote Originally Posted by MattF View Post
    Code:
    foreach ($_POST['C_0'] as $key => $val)
    {
        print($val.', '.$_POST['C_1'][$key].', '.$_POST['C_2'][$key]);
    }
    so its this simple? i didnt realize you could nest them inside the foreach. man i feel like a idiot, lol thanks matt


  •  

    Posting Permissions

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