Unable to print form element I am not able to get form element qty twice. I have 2 line item IDs, but I am getting 1 instead of printing qty twice. Please help me out this. This is my code.

function mol_split_delivery_form($form, &amp;$form_state, $order_id) {

$order = arg(1);
$line_item_idds = get_total_line_item_ids($order);

if (!empty($line_item_idds)) {
  $line_items = commerce_line_item_load_multiple($line_item_idds);

}
else {
  $line_items = array();
}

foreach ($line_items as $line_item_id =&gt; $line_item) {

$form = array();
$option_first = array(1 =&gt; '1', 2 =&gt; '2', 3 =&gt; '3', 4 =&gt; '4', 5 =&gt; '5', 6 =&gt; '6', 7 =&gt; '7', 8 =&gt; '8', 9 =&gt; '9');
$form['line_items'][$line_item_id]['quantity'] = array(
    '#title' =&gt; 'Qty',
    '#type' =&gt; 'select',
    '#options' =&gt; $option_first,
    '#default_value' =&gt;  $line_item-&gt;quantity,
 );

 }
return $form;
}
Take the $form = array(); line out of the foreach loop. This is clearing the $form array every time it loops around. You don't want it to do that.

foreach ($line_items as $line_item_id =&gt; $line_item) {

   $option_first = array(1 =&gt; '1', 2 =&gt; '2', 3 =&gt; '3', 4 =&gt; '4', 5 =&gt; '5', 6 =&gt; '6', 7 =&gt; '7', 8 =&gt; '8', 9 =&gt; '9');

   $form['line_items'][$line_item_id]['quantity'] = array(
     '#title' =&gt; 'Qty',
     '#type' =&gt; 'select',
     '#options' =&gt; $option_first,
     '#default_value' =&gt;  $line_item-&gt;quantity,
   );
}


Also, if $order_id is a argument, you should not need to call arg(1). Consider passing the commerce order object as an argument instead, using %commerce_order as a URL parameter. Drupal will load it and pass it for you (if this function is a menu item callback).