从php中的另一个数组创建一个数组我有一个像这样的数组。这是一个二维数组。$MainArray = Array(
[0] => Array
(
[Job_Name] => WXYZ [Quantity] => 1000
[Machine_Name] => Machine1
[Start_Date] => 2014-07-30 00:00:00
[Completion_Date] => 2014-08-02 00:00:00
[Labor] => 4
)
[1] => Array
(
[Job_Name] => ABCD [Quantity] => 1500
[Machine_Name] => Machine2
[Start_Date] => 2014-08-08 00:00:00
[Completion_Date] => 2014-08-14 00:00:00
[Labor] => 2
)
[2] => Array
(
[Job_Name] => BCDA [Quantity] => 1200
[Machine_Name] => Machine1
[Start_Date] => 2014-08-02 00:00:00
[Completion_Date] => 2014-08-07 00:00:00
[Labor] => 1
)
)我想使用这些信息来创建一个新的三维数组,它看起来像这样。$ConvertedArray = Array(
[Machine1] => Array
(
[0] => Array
(
[Job_Name] => WXYZ [Quantity] => 1000
[Start_Date] => 2014-07-30 00:00:00
[Completion_Date] => 2014-08-02 00:00:00
[Labor] => 4
)
[1] => Array
(
[Job_Name] => BCDA [Quantity] => 1200
[Start_Date] => 2014-08-02 00:00:00
[Completion_Date] => 2014-08-07 00:00:00
[Labor] => 1
)
)
[Machine2] => Array
(
[0] => Array
(
[Job_Name] => ABCD [Quantity] => 1500
[Machine_Name] => Machine2
[Start_Date] => 2014-08-08 00:00:00
[Completion_Date] => 2014-08-14 00:00:00
[Labor] => 2
)
) )如对此有任何帮助,将不胜感激。我被某些东西困住了,需要弄清楚如何使用这个原始数组来创建新的数组。因此,基本上,我将来自每台机器的所有作业分组在一起,而这些作业的键取决于它们在原始数组中的位置。因此,如果原始数组有一个带有键2的作业,而该机器上没有其他作业具有较高的键,那么它将成为该作业的键0,并创建一个具有该机器名的新键。我真的很感谢你在这方面的帮助。
2 回答
湖上湖
TA贡献2003条经验 获得超2个赞
foreach ($MainArray as $value) { $name = $value['Machine_Name']; unset($value['Machine_Name']); $ConvertedArray[$name][] = $value;}
- 2 回答
- 0 关注
- 650 浏览
添加回答
举报
0/150
提交
取消