dongtang3155 2014-08-21 06:09
浏览 35

将多维数组拆分为更小的数组

I have a multidimensional array that looks like this:

{
  "groups": [
    {
      "__v": 0,
      "_create_date": "2014-08-20T23:00:12.901Z",
      "_id": "53f5287ca78473a969001827",
      "_last_message_date": "2014-08-20T23:04:36.347Z",
      "activity": 0,
      "blocked_users": [],
      "created_by": {
        "_id": "53e84b0eba84943c6d0003f8",
        "_last_modified": "2014-08-20T00:11:05.399Z",
        "first_name": "Jegg",
        "last_name": "V"
      },
      "curated": false,
      "diversity": 0,
      "featured": false,
      "flagged": false,
      "last_message": {
        "text": "let's talk beo",
        "created_by": {
          "_id": "53e84b0eba84943c6d0003f8",
          "first_name": "Jegg",
          "last_name": "V"
        },
        "_id": "53f52984a78473a969001833",
        "_create_date": "2014-08-20T23:04:36.347Z"
      },
      "member_count": 1,
      "messages_count": 1,
      "name": "Test",
      "public": true,
      "recency": 52182276.347,
      "score": 52182276.347,
      "tags": []
    },

This structure repeats over 3000 times creating a very large multidimensional array. I think I can use array_chunk($array, 300) to break the array into smaller chunks. But I can't figure out how to access them exactly.

What I want to do is independently loop through the newly chunked arrays. So I'd like to end up with something like:

$array1 = {...}
$array2 = {...}
$array3 = {...}
$array4 = {...}

... and so on

THen I could loop through each of the newly created arrays, which are essentially smaller groups of the original array, but of 3000 arrays in one multidimensional array as I have in the first place, I end up with these smaller ones of 300 arrays each.

I hope this makes sense, I'm kinda out of my league. Help is always appreciated.

  • 写回答

2条回答 默认 最新

  • doufei4923 2014-08-21 06:23
    关注

    I think your array is in json format.

    First decode it and then pass to array_chunk method.

    array_chunk($input_array, 300));
    

    then access them as $input_array[0][0], $input_array[0][1]....... $input_array[0][299], $input_array[1][0], $input_array[1][1].....

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分