php - How many arrays does array_chunk return? -


how know amount of arrays php chunk function returns?

for example, if execute piece of code know it'll return 3 arrays, how calculate it:

$input_array = array('a', 'b', 'c', 'd', 'e'); print_r(array_chunk($input_array, 2)); 

output:

array (     [0] => array         (             [0] =>             [1] => b         )      [1] => array         (             [0] => c             [1] => d         )      [2] => array         (             [0] => e         )  ) 

you can calculate programmatically dividing number of values in array should chunked chunk size:

$input_array = array('a', 'b', 'c', 'd', 'e'); $chunksize = 2; print_r(array_chunk($input_array, $chunksize));   $count = round(count($input_array) / $chunksize,php_round_up); 

i'm using php_round_up because last chunk doesn't neccessarly have chunk size values, array, too.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -