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

Thread: foreach loops

  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    foreach loops

    I have the following setup. I want to pass an array from the lower foreach loop to the upper foreach loop when I submit the former. I don't really know what I'm doing -relying more on logic than knowledge of syntax - but this doesn't work. What am I doing wrong? Thanks guys.

    PHP Code:
    foreach ($_POST['emailto'] as $send) { 
    echo 
    $send;
    }
    exit();

    $i=0;
    $emailto=array();

    foreach (
    $_POST['email'] as $sendto) { 
    echo(
    "<input type='hidden' name='emailto[".$i."]' value='".$sendto."'>");
    $i++;
    // and other stuff that works OK


  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    Grahamstown, South Africa
    Posts
    237
    Thanks
    6
    Thanked 17 Times in 17 Posts

    Macintosh

    I dont think you can have multiple values for one array key.... So for example when you take $_POST['email'] there will only be one value.... you cannot run a foreach command on that.

    Try changing your code so that you run a foreach on only the $_POST. and not on individual keys.

    eg.
    PHP Code:
    foreach ($_POST as $value){
            echo(
    $value);
    }
    //not
    foreach ($_POST['some_value']){

    or just try re-evaluating your code.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, that didn't work out at all so I completely changed the code. Thanks anyway.


  •  

    Posting Permissions

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