2015-08-28 40 views
-2

我使用https://github.com/yapapaya/jquery-cloneya創建多個表單輸入這樣的:組插入陣列具有獨特的鍵

create_order_shirt_shoulder[0] // name of the form 
create_order_shirt_chest[0] // name of the form 

而且我可以複製這種形式的容器,這將導致到:

create_order_shirt_shoulder[1] // name of the form 
create_order_shirt_shoulder[2] // name of the form 
... 

我插入代碼看起來像

foreach ($_REQUEST as $key => $val) 
{ 
    if (is_array($val)) { 
     foreach ($val as $value) 
     { 
      $value = strip_tags($value); 

      $items = array(
       'order_item_reference' => $reference, 
       'order_item_key' => $key, 
       'order_item_value' => $value, 
       'order_item_group' => " " // group id 
      ); 

      $this->db->insert('user_orders_items', $items); 
     } 
    } 
} 

我想用一個唯一的密鑰分組每個數組, ets說屬於[0]的所有數組在我的order_item_group列中有「#1」

在此先感謝。

+0

你能解釋更多你想要做什麼? – Viral

+0

*我有一個表單輸入,像這樣'create_order_shirt_shoulder [0]'* - 我可能會誤解,但它看起來不像*表單輸入*。 –

+0

是不明白你的問題。你能詳細闡述一下嗎? – CodeGodie

回答

1

如何使用子數組中的鍵將子數組中的所有相關項組合在一起?

例如:

foreach ($_REQUEST as $key => $val) 
{ 
    if (is_array($val)) { 
     foreach ($val as $groupId => $value) 
     { 
      $value = strip_tags($value); 

      $items = array(
       'order_item_reference' => $reference, 
       'order_item_key' => $key, 
       'order_item_value' => $value, 
       'order_item_group' => $groupId // group id 
      ); 

      $this->db->insert('user_orders_items', $items); 
     } 
    } 
} 
+0

正確! ... 非常感謝 :) – Shina