Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2003
    Location
    UK
    Posts
    27

    Red face Unanswered: RE: Parsing an Array via a Form

    Is it possible to pass an array via a form to another page?

    i know i could do this via a long winded method of using for and count functions, but is there an easier way?

    cheers
    phil

  2. #2
    Join Date
    Jan 2003
    Location
    UK
    Posts
    27

    Wink Done it....... Cheers

    Got around the problem in the end..... rather cleverly i think too........

    Not sure if this'll help anyone, but here is the code i used, it makes use of a "variable variable" (i.e. $$) to rebuild the array..........

    <?php
    if (!$x) {
    /* Post Array */
    $myArray = array('fruit','apple','veggie','carrot','banana',' pear');
    $x = count($myArray) - 1;
    print " <form>\n";
    for ($i = 0; $i <= $x; $i++) {
    print " <input type='hidden' name='myArray$i' value='" . $myArray[$i] . "'>\n";
    }
    print " <input type='hidden' name='x' value='$x'>\n";
    print " <input class='InputBox' type='Submit' value='Update'>\n";
    print " </form>\n";
    } else {
    /* Re-build Array into the variable $myArray*/
    for ($i = 0; $i <= $x; $i++) {
    $ArrayArray = "myArray$i";
    $myArray[$i] = $$ArrayArray;
    }
    /* Print Array */
    for ($i = 0; $i <= $x; $i++) {
    print $myArray[$i] . "<br>\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
  •