【发布时间】:2014-11-19 21:31:04
【问题描述】:
我有一个这样结构的数组(这是 CSV 格式化它的方式):
Array(
0 => Array(
0 => person1
1 => person2
2 => person3
//all the way to 9
),
1 => Array(
0 => id belonging to person 1
1 => id belonging to person 2
2 => id belonging to person 3
),
2 => Array(
0 => id belonging to person 1
1 => id belonging to person 2
2 => id belonging to person 3
),
//all the way to 20
)
我正在尝试对一个新数组(数组)进行排序,每个索引都是与上面0 索引中的键对应的值。即,person1 指向一个数组,其中所有 id 都来自外部数组 1-20。
在索引0之后的每个数组中,都包含20个id,0属于第一个数组中的key 0。
我试图实现的结构如下所示:
Array(
[person1] => Array(
id belonging to person 1
id belonging to person 1
id belonging to person 1
),
[person2] => Array(
id belonging to person 2
id belonging to person 2
id belonging to person 2
),
[person3] => Array(
id belonging to person 3
id belonging to person 3
id belonging to person 3
),
)
到目前为止,我的尝试已经奏效,但是,我不得不对一些索引进行硬编码。实现所需结构的最佳解决方案是什么?
【问题讨论】:
标签: php arrays data-structures