我有一个看起来像这样的数组:
我需要将其翻译为:
Some things to know about the $startArray
is that it is dynamic based on the amount of people submitted on a form. Each person always has just those three fields though (custom_12
, custom_13
, custom_14
aka fName
, lName
, email
). So if there were 5 members, the 5th members fName
would be the key custom_12-5
in the start array.
I've been looking around on stackoverflow for a question just like this and I was not able to find one. What would be the steps taken and possible array functions or anything else for creating the $endArray
?
There's actually a builtin function for this: https://www.php.net/manual/en/function.array-chunk.php
For example,
array_chunk($startArray, 3)
will give you the base for your new array, you'll just need to then iterate through it and rename the keys.另外,您可以自己遍历数组,然后根据当前迭代的索引将值添加到新数组中。
感谢查理的建议,我想到了这一点。
输出正是我想要的: