Adding array to multidimensional array

Discussion in 'PHP' started by AnonymousUser, Dec 21, 2008.

  1. #1
    Hey, I have been having ALOT of trouble with this code, I belive it will be a simple task to some1 who has a bit more knowledge then me.

    <form method="POST">
    <input value="Ny" name="State[Ny][]" />
    <textarea name="State[Ny][0]"></textarea>
    <input type="submit" /></form>
    
    <?php
    $State = $_POST['State'];
    
    print "<PRE>"; print_r($State); print "</PRE>";
    
       foreach($State as $StateId)
       {
          $New = implode("\n",$StateId);
          $New = explode("\n",$New);
          print "<PRE>"; print_r($New); print "</PRE>";
       }
    ?>
    
    PHP:
    This produces this

    Array
    (
        [Ny] => Array
            (
                [0] => this is line 1 ny
    this is line 2 ny
            )
    
    )
    
    Array
    (
        [0] => this is line 1 ny
        [1] => this is line 2 ny
    )
    PHP:
    What I need to achive is this

    Array
    (
        [Ny] => Array
            (
                [0] => this is line 1 ny
                [1] => this is line 2 ny
            )
    
    )
    
    PHP:
    Ive been trying to solve this problem for too many hours now, Its very frustraiting. The furthest Ive gotten is adding those values in the main array under Ny, But not in Ny

    Thanks in advance, Hope to hear some replies
     
    AnonymousUser, Dec 21, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Have you tried:
    <input value="Ny" name="State[Ny][1]" />
    Code (markup):
    Instead of:
    <input value="Ny" name="State[Ny][]" />
    Code (markup):
    Jay
     
    jayshah, Dec 21, 2008 IP
    AnonymousUser likes this.
  3. AnonymousUser

    AnonymousUser Peon

    Messages:
    593
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Forgot to post, Its completed now, Thx for the post jay. I did it another way.
    Repped anyway
     
    AnonymousUser, Dec 21, 2008 IP