0

无论如何要使用php获取每个profile_id的前两个元素

array(
    array(['type'] => album,['profile_id'] => 1),
    array(['type'] => video,['profile_id'] => 1),
    array(['type'] => image,['profile_id'] => 1),

    array(['type'] => album,['profile_id'] => 2),
    array(['type'] => video,['profile_id'] => 2),
    array(['type'] => scenes,['profile_id'] => 2),
    array(['type'] => image,['profile_id'] => 2),

    array(['type'] => album,['profile_id'] => 3),
    array(['type'] => video,['profile_id'] => 3),
    array(['type'] => album,['profile_id'] => 3),
)   

预期结果

array(
    array(['type'] => album,['profile_id'] => 1),
    array(['type'] => video,['profile_id'] => 1),

    array(['type'] => album,['profile_id'] => 2),
    array(['type'] => video,['profile_id'] => 2),

    array(['type'] => album,['profile_id'] => 3),
    array(['type'] => video,['profile_id'] => 3),
)

谢谢

4

1 回答 1

0
  • 循环数组
  • 如果 profile_id == next profile_id,则放入新数组最多计数 2
  • 如果 profile_id != next profile_id 重置计数并重复步骤 2。

最好不要发布确切的代码。:D

于 2012-06-14T09:32:45.790 回答