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. how long does viagra last http://viagwdp.com/ buy sildenafil online europe

    Reply
  2. 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
  3. 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
  4. 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
  5. Howdy just wanted to give you a quick heads up. The text in your content seem to be running off the screen in Firefox. I'm not sure if this is a formatting issue or something to do with browser compatibility but I thought I'd post to let you know. The design and style look great though! Hope you get the issue solved soon. Many thanks

    Reply
  6. Oh my goodness! Amazing article dude! Thank you, However I am having problems with your RSS. I don't understand why I am unable to subscribe to it. Is there anybody else having identical RSS problems? Anyone that knows the solution can you kindly respond? Thanx!!

    Reply