我有一个如下所示的键值列表:
running: "yes"
running_where: "to the store"
running_why: "because"
walking: "yes"
someotherkey: "some non related value"
walking_where: "over there"
walking_why: "mom told me to"
running: "yes"
running_where: "to the bank"
yetanotherkey: "yet another non related value"
running_why: "broke"
等等。分组是有序的(但有时我想完全忽略分组中的其他键),并且我想通过对相关项进行分组将其转换为可用的数组,在上面的情况下会给我: / p>
Array
(
[0] => Group
(
[running] => yes
[running_where] => to the store
[running_why] => because
)
[1] => Group
(
[walking] => yes
[walking_where] => over there
[walking_why] => mom told me to
)
[2] => Group
(
[running] => yes
[running_where] => to the bank
[running_why] => broke
)
)
PHP中最简单的方法是什么?我已经看过类似的问题,但尚未找到适用的问题。
答案 0 :(得分:2)
试试这段代码,
array_chunk($array, 3);