D7: How to loop an array as form elements? I have the following hook_form (below) which colect data from $_POST and then send them via email. The problem is $jcartItemName and $jcartItemPrice are arrays so I need to loop through them and display the form items accordingly. I expect this could be done via a 

foreach($jcartItemName as $value) { 
    $form['jcartItemName'] = array(
    '#type' =&gt; 'textfield',
    '#value' =&gt; isset($value) ? $value : '',
    );
}


but how do I do that effectively. Thanks!

function checkout_form($form, &amp;$form_state) {
     $jcartItemName = $_POST['jcartItemName'];//array
     $jcartItemPrice = $_POST['jcartItemPrice'];//array
     $jcartTotalPrice = array_sum($jcartItemPrice);//integer
     $form = array();
     $form['#action'] = "";

    $form['jcartItemName'] = array(
    '#type' =&gt; 'textfield',
    '#value' =&gt; isset($jcartItemName) ? $jcartItemName : '',
    );


    $form['jcartTotalPrice'] = array(
    '#title' =&gt; t('TotalPrice'),
    '#type' =&gt; 'textfield',
    '#value' =&gt; isset($jcartTotalPrice) ? $jcartTotalPrice : '',

    );

        $form['email'] = array(
        '#type' =&gt; 'textfield',
        '#title' =&gt; t('E-mail'),
        '#default_value' =&gt; "",

        '#description' =&gt; "Please enter your e-mail for order to be sent.",

    );

    $form['send-order'] = array(
        '#type' =&gt; 'submit',
        '#name' =&gt; 'send-order',
        '#value' =&gt; t('Send Order'),
        '#class' =&gt; 'button',
    );

    return $form;
  }
For those of you who face the same issue: I found the answer:

foreach($jcartItemName as $key =&gt; $value) { 
$form['jcartItemName'][$key] = array(
'#type' =&gt; 'textfield',
'#value' =&gt; isset($value) ? $value : '',
);