按列对二维数组进行分组,并从分组子数组中删除分组列
鉴于我的数组
array [0]
fielda: cca
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [1]
fielda: cca
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [2]
fielda: cca
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [3]
fielda: ccb
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [4]
fielda: ccb
fieldb: my value b
fieldc: my value c
fieldd: my value d
是否有一种简单的方法来重组它,以便 fielda 像这样分组
array [0]
fielda: cca
array [0]
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [1]
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [2]
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [3]
array [1]
fielda: ccb
array [0]
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [1]
fieldb: my value b
fieldc: my value c
fieldd: my value d
Given my Array
array [0]
fielda: cca
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [1]
fielda: cca
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [2]
fielda: cca
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [3]
fielda: ccb
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [4]
fielda: ccb
fieldb: my value b
fieldc: my value c
fieldd: my value d
Is there a simple way to restructure it so that fielda is grouped like so
array [0]
fielda: cca
array [0]
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [1]
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [2]
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [3]
array [1]
fielda: ccb
array [0]
fieldb: my value b
fieldc: my value c
fieldd: my value d
array [1]
fieldb: my value b
fieldc: my value c
fieldd: my value d
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许有一种更简单的方法,但这应该适合您:
DEMO: http://codepad.org/M26yBLL4
Maybe there's a simpler way, but this should work for you:
DEMO: http://codepad.org/M26yBLL4
像这样的东西应该有效:
Something like this should work: