我有一個來自表單POST的數組,我想將它們組合在一起。使用表單域創建PHP數組
我的第一次嘗試是在數組上運行一個foreach循環,但我沒有成功將邏輯分組。我有用按鍵編號創建動態數組的想法,但我無法獲取該數字。
初始陣列:
["affix-1-order"]=> "1";
["affix-1-type"]=> "Apple";
["affix-1-count"]=> "5";
["affix-3-order"]=> "2";
["affix-3-type"]=> "Orange";
["affix-3-count"]=> "10";
["affix-2-order"]=> "3";
["affix-2-type"]=> "Banana";
["affix-2-count"]=> "3";
["affix-4-order"]=> "4";
["affix-4-type"]=> "Mango";
["affix-4-count"]=> "15";
預期輸出:
["1"]=> [{
["type"]=> "Apple",
["count"]=> "5",
["order"]=> "1"
}],
["2"]=> [{
["type"]=> "Banana",
["order"]=> "3",
["count"]=> "3"
}],
["3"]=> [{
["type"]=> "Orange",
["order"]=> "2",
["count"]=> "10",
}],
["4"]=> [{
["type"]=> "Mango",
["order"]=> "4",
["count"]=> "15"
}];
讓你有在後所需的數組,你可以建立自己的形式進行任何操作上 – 2014-01-10 03:12:07
後者我不明白?你如何建議我在表單輸入中分組鍵和3個值? – veksen
'name = X [] ['type']''name = X [] ['order']''name = X [] ['count']',帖子X數組將會是你想要的 – 2014-01-10 03:35:48