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 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    array_combine modification

    When I print_r($_POST) to determine what's being posted from my form, I get this:

    PHP Code:
    Array ( [name] => Array ( [0] => Joe [1] => [2] => [3] => [4] => [5] => ) [animal] => Array ( [0] => Dog  [1] => Cat [2] => [3] => [4] => [5] => ) [submit] => Validez 
    Then, I array_combine to (duh) combine the arrays, and I get this:

    PHP Code:
    Array ( [Joe] => Dog [] => ) 

    I'd like to get this:

    PHP Code:
    Array ( [Joe] => Dog [] => Cat
    Anyone know how I can accomplish this?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    If I understand you right, you want to combine the elements in the array assigned to $_POST['name'] and the elements in the array assigned to $_POST['animal'], so that the $_POST['name'] elements become the keys and $_POST['animal'] elements become the values.

    Is that right?

    I think array_combine will work for you. You said you tried it but you didn't show us the code you used.
    PHP Code:
    if (is_array($_POST['name']) && is_array($_POST['animal'])) {
        
    $newArray array_combine($_POST['name'], $_POST['animal']);

    That should work fine.

    p.s. Wrapping print_r() in <pre> tags makes it readable.
    PHP Code:
    print "<pre>\n";
    print_r($_POST);
    print </
    pre>n"; 


  •  

    Posting Permissions

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