如何合理化PHP中的多维数组?
我一整天都在尝试这个! 我如何将顶部多维数组转换为底部。
Array (
[0] => Array ( [id] => 34 [email] => [email protected] )
[1] => Array ( [id] => 34 [email] => [email protected] )
[2] => Array ( [id] => 33 [email] => [email protected] )
[3] => Array ( [id] => 33 [email] => [email protected] )
[4] => Array ( [id] => 33 [email] => [email protected] )
)
Array (
[0]=>Array ([id] => 34 [email] => Array ([0]=> [email protected] [1]=>[email protected] )
[1]=>Array ([id] => 33 [email] => Array ([0]=> [email protected] [1]=>[email protected] [2]=>[email protected])
)
非常感谢。
I've been trying this all day!
How would I convert the top multidimensional array into the bottom.
Array (
[0] => Array ( [id] => 34 [email] => [email protected] )
[1] => Array ( [id] => 34 [email] => [email protected] )
[2] => Array ( [id] => 33 [email] => [email protected] )
[3] => Array ( [id] => 33 [email] => [email protected] )
[4] => Array ( [id] => 33 [email] => [email protected] )
)
Array (
[0]=>Array ([id] => 34 [email] => Array ([0]=> [email protected] [1]=>[email protected] )
[1]=>Array ([id] => 33 [email] => Array ([0]=> [email protected] [1]=>[email protected] [2]=>[email protected])
)
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一个循环生成一个与 id 字段无关的数组,并简单地将每个电子邮件地址推入其中。然后,第二个循环获取该中间数组并在其周围包装另一个数组以获取 0,1 等...键。
The first loop produces an array keyed off the id fields, and simply pushes each email address onto it. The second loop then takes that intermediate array and wraps another array around it for the 0,1,etc... keys.
仅仅使用密钥来存储 ID 不是更简单的方法吗?像这样:
那么对电子邮件进行分组将成为一项微不足道的任务。
Would not just using keys in order to store IDs be an easier way to do that? Like this:
Then grouping emails would become a trivial task.