douyi1899 2011-11-05 15:40
浏览 41
已采纳

将数组转换为二维数组并删除前11个条目

I have been trying to figure this out until my brain imploded. Im trying to sort an array.

The first 11 entries has to be removed, then the next 7 entries has to be placed in an new array and then the next 7 entries and so on. Until there is no more entries.

Short example:

Turn this:

Array (
     [0] => 0
     [1] => 1
     [2] => 2
     [3] => 3
     [4] => 4
     [5] => 5
     [6] => 6
     [7] => 7
     [8] => 8
     [9] => 9
     [10] => 10
     [11] => 11
     [12] => 12
     [13] => 13
     [14] => 14
     [15] => 15
     [16] => 16
     [17] => 17
     [18] => 18
)

Into this:

Array (
     [0] => Array (
               [0] => 11
               [1] => 12
               [2] => 13
               [3] => 14
               [4] => 15
               [5] => 16
               [6] => 17
            )
)
  • 写回答

3条回答 默认 最新

  • dsxon40042 2011-11-05 15:49
    关注

    Something like this should do the trick:

    $orig = array(...);
    
    $i = 11; // start at offset 11
    $remove = 7; // take off 7 at a time
    
    $new = array();
    while($i <= count($orig)) {
       $new[] = array_slice($orig, $i, $remove);
       $i += $remove;
    }
    

    $new will have your new multi-dimensionalized array

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?