且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在PHP中按列拆分二维数组

更新时间:2023-02-22 22:12:57

您或多或少都拥有解决方案.

You more or less have what I would have arrived at for a solution.

只要您希望用作索引的数据始终位于数组中的相同位置,就可以像在收集器数组中一样对索引进行硬编码.

As long as the data that you wish to use as an index will always be in the same position in the array, you will be able to hardcode the index as you have done in the collector array.

如果没有,我会考虑移动到关联数组,并在创建数组时为要用作索引的值分配名称.

If not, I would think about moving to an associative array and assigning a name to the value that you want to use as an index when creating the array.

[['a', 'index'=>1] [etc...]]

$out[$i[index]][] = $i;