drxp993551 2017-04-14 12:09
浏览 19
已采纳

PHP:将大型数组总结为10个数组的最有效方法是什么?

My web app returns to the user all images in a specific folder (pictures taken for each day in the month) via array of filenames. Issue is that sometimes the number of images are just too many (30-500 images).

What i wanted to do is provide a summary of that array, by reducing that array to just 10 images. I could easily get the first 10 by limiting the loop. But that just represents the first part (for few images of the day) . I wanted to get 10 images from that array in a way that the 10 images is equally spread out throughout the day.

I could think of several ways to do this but involving quite a lot of code.

Was wondering if anyone knows of a cool array function or method that solves this problem?

  • 写回答

2条回答 默认 最新

  • duangaoe9401 2017-04-14 12:17
    关注

    There is no built-in function in php for do that. The best thing I think is using of sizeof() function:

    $size = sizeof($array);
    $chunkSize = ceil($size/10);
    for($i = 0;$i<$size;$i+=$chunkSize){
        echo $array[$i];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)