Arrays and Forms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Craig Keightley

    #1

    Arrays and Forms

    I have two elements in a form , a text area (justification[]) and a hidden
    field (prodID[])

    I have the following code as a test:

    foreach($_POST['justification'] as $reason) {
    echo $reason."<br>";
    }
    foreach($_POST['prodID'] as $pID) {
    echo $pID."<br>";
    }

    output
    item reason
    item reason 2
    item reason 3
    item reason 4

    id1
    id2
    id3
    id4



    How can i edit the code as such so that the following out put is displayed:

    item reason - id
    item reason 2 - id2
    item reason 3 - id3
    item reason 4 - id4


    Many Thanks for any help in advance

    Craig



  • Bzdziul

    #2
    Re: Arrays and Forms

    U¿ytkownik "Craig Keightley" <dont@spam.me > napisa³ w wiadomo¶ci
    news:429306d5$0 $290$cc9e4d1f@n ews-text.dial.pipex .com...[color=blue]
    > I have two elements in a form , a text area (justification[]) and a hidden
    > field (prodID[])
    > I have the following code as a test:
    > foreach($_POST['justification'] as $reason) {
    > echo $reason."<br>";
    > }
    > foreach($_POST['prodID'] as $pID) {
    > echo $pID."<br>";
    > }[/color]

    for($i=0;$i<cou nt($_POST['prodID']);$i++)
    echo $_POST['justification'][$i].' - '.$_POST['prodID'][$i];

    Comment

    • Philip  Olson

      #3
      Re: Arrays and Forms

      foreach ($_POST['justification'] as $id => $reason) {

      echo $reason;
      echo $_POST['prodID'][$id];

      }

      Comment

      Working...