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 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question $_POST a 2D array?

    I have an unknown number of check-boxes in a form (generated by php) that the end-user will tick. How can I do 2D arrays for that?

    I.e.

    OptionA:
    [ ] Tickbox 1
    [ ] Tickbox 2
    [ ] Tickbox 3

    OptionB:
    [ ] Tickbox 1
    [ ] Tickbox 2
    [ ] Tickbox 3

    And then get the values like:

    _POST[OptionA][1,2,3,4,5..]
    _POST[OptionB][1,2,3..]

    etc.?

    Thanks!
    Last edited by john6; 10-10-2012 at 06:51 AM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,197
    Thanks
    23
    Thanked 605 Times in 604 Posts
    easier than me trying to explain: http://www.w3schools.com/html/html_forms.asp

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    You use a foreach loop. The example below is a quick one so there might be syntax errors. You can also assign the output to variables, instead of echoing it out.

    PHP Code:
    $array _POST['OptionA']; // 0,1,2,3,4,5,6 .........

    foreach ($array as $value) {
    echo 
    "$value";



    -----
    Leonard Whistler

  • #4
    New Coder
    Join Date
    Aug 2010
    Posts
    53
    Thanks
    6
    Thanked 1 Time in 1 Post
    Try using an array + foreach loop:

    PHP Code:
    $arr = array ('options' => $_POST['option1'], $_POST['option2'],$_POST['option3'], $_POST['option4']); 
    $output"";
    foreach (
    $arr as $arr) {    
     
    $value .= $arr.", ";
    }
    echo 
    $output
    You can store the $output into your database, however it may be difficult to analyze the data after... There is better method to store multiple values for data analysis but that's my 2 cents.


  •  

    Posting Permissions

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