dousi4950 2016-03-27 16:10
浏览 35

初学者PHP - 在php中分离一个数组[关闭]

I'm a beginner at php and hopefully someone can help me. I have an array with 10 items and I need the first element to be 1 instead of zero. **I also need to have the array split into 2 columns beside each other with the first 5 elements in one column and the second 5 in the second. I've tried using html but could not get it to work. When I use the slice in php the last element(5) in the first column disappears.. So let's say my array is as follows:

$farmland=array("Duck","Fox","Goose","Cow","Cat","Rabbit","Bull","Mouse","Sheep","Goat");

I need it to appear like this:

Duck       Rabbit
Fox        Bull
Goose      Mouse
Cow        Sheep
Cat        Goat
  • 写回答

2条回答 默认 最新

  • dqqy64515 2016-03-27 16:16
    关注

    Simplest way to split array into chunks is array_chunk:

    $farmland = array("Duck","Fox","Goose","Cow","Cat","Rabbit","Bull","Mouse","Sheep","Goat");
    $chunks = array_chunk($farmland, 5);  // get chunks with size of 5
    
    print_r($chunks);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题