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. Definitely believe that which you stated. Your favorite reason seemed to be on the web the simplest thing to be aware of. I say to you, I certainly get irked while people think about worries that they plainly don't know about. You managed to hit the nail upon the top and defined out the whole thing without having side-effects , people can take a signal. Will probably be back to get more. Thanks

    Reply
  2. I love it whenever people get together and share thoughts. Great site, stick with it!

    Reply
  3. Greetings from Colorado! I'm bored to death at work so I decided to browse your site on my iphone during lunch break. I really like the information you present here and can't wait to take a look when I get home. I'm shocked at how quick your blog loaded on my mobile .. I'm not even using WIFI, just 3G .. Anyhow, superb blog!

    Reply
  4. Hello there! I could have sworn I've been to this site before but after going through a few of the posts I realized it's new to me. Anyhow, I'm certainly happy I found it and I'll be bookmarking it and checking back regularly!

    Reply
  5. Yesterday, while I was at work, my sister stole my iPad and tested to see if it can survive a 40 foot drop, just so she can be a youtube sensation. My iPad is now broken and she has 83 views. I know this is totally off topic but I had to share it with someone!

    Reply
  6. daftar slot

    Reply