array_chunk() Function in PHP

The array_chunk() Function is split an array into chunks of new array. The array_chunk() function mostly use when we work on slider like or list.

array_chunk(array,Number for size,preserve_key);

preserve_key is Optional and only two Possible values:
true – Preserves the keys
false – Default. Reindexes the chunk numerically

Example:
Split in just two array chunks

<?php
$alphabets =array(“A”,”B”,”C”,”D”,”E”,”F”);
print_r(array_chunk($alphabets,2));
?>

Split array with preserve key.

<?php
$alphabets =array(“A”=>”1″,”B”=>”2″,”C”=>”3″,”C”=>”4”);
print_r(array_chunk($alphabets ,2,true));
?>

News Reporter
IT Software and web development, Core PHP, JavaScript, JQuery, HTML, CSS, CakePHP, Angularjs, Codeigniter etc.

2 thoughts on “array_chunk() Function in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

error: