PHP函数array_chunk()分割数组

array_chunk() 把一个数组分割成新的数组块

array array_chunk(array $array,int $size[,bool preserve_key])

参数描述:array是分割的数组

size规定每个新数组包含的元素,最后一个数组可能会少几个元素

preserve_key:可选,有两个选项:true,保留原始数组中的键名;false,默认选项,每个结果数组使用从0开始的新数组索引

示例:

$array = array(
    'a'=>'JAVA',
    'b'=>'PHP',
    'c'=>"C++",
    'd'=>'c#',
    'e'=>'perl'
);
print_r(array_chunk($array,2,false));
echo PHP_EOL;
print_r(array_chunk($array,2,true));

运行结果如下:

Array ( [0] => Array ( [0] => JAVA [1] => PHP ) [1] => Array ( [0] => C++ [1] => c# ) [2] => Array ( [0] => perl ) )

Array ( [0] => Array ( [a] => JAVA [b] => PHP ) [1] => Array ( [c] => C++ [d] => c# ) [2] => Array ( [e] => perl ) )
Responses / Cancel Reply
  1. You ought to be a part of a contest for one of the most useful blogs on the web. I most certainly will recommend this website!

    Reply
  2. Hmm it looks like your site ate my first comment (it was super long) so I guess I'll just sum it up what I submitted and say, I'm thoroughly enjoying your blog. I as well am an aspiring blog blogger but I'm still new to everything. Do you have any tips for rookie blog writers? I'd definitely appreciate it.

    Reply
  3. how long does viagra last http://viagwdp.com/ buy sildenafil online europe

    Reply
  4. Great article! That is the kind of information that are meant to be shared across the web. Shame on Google for not positioning this publish higher! Come on over and talk over with my site . Thanks =)

    Reply
  5. You are so cool! I do not think I have read through a single thing like this before. So nice to discover somebody with a few unique thoughts on this subject matter. Seriously.. many thanks for starting this up. This web site is something that is required on the web, someone with some originality!

    Reply
  6. Hey there! I just wanted to ask if you ever have any issues with hackers? My last blog (wordpress) was hacked and I ended uup losing months of hard work due to no data backup. Do you have anny solutions to stop hackers?

    Reply