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
  1. Hey! I'm at work surfing around your blog from my new iphone 3gs! Just wanted to say I love reading through your blog and look forward to all your posts! Keep up the superb work!

    Reply
  2. This post presents clear idea designed for the new viewers of blogging, that actually how to do running a blog.

    Reply
  3. Incredible points. Sound arguments. Keep up the good spirit.

    Reply
  4. Attractive component of content. I just stumbled upon your blog and in accession capital to claim that I get in fact enjoyed account your weblog posts. Anyway I'll be subscribing on your feeds or even I achievement you access consistently fast.

    Reply
  5. Hey, I think your site might be having browser compatibility issues. When I look at your blog in Opera, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, great blog!

    Reply
  6. Everyone loves it when people come together and share thoughts. Great site, continue the good work!

    Reply