PHP Programing language

array_chunk() Function in PHP
Previous Home Next

array_chunk()

The array_chunk() function splits an array into chunks of new arrays.

Syntax:
array_chunk(array,size,preserve_key);

In above syntax, "array" specifies the array to use, "size" is an integer that specifies the size of each chunk and "preserve_key" preserve_key values are as follows:

  • true: Preserves the keys
  • false: Default and reindexes the chunk numerically

 

Example:

<?php
$fruit_weight=array("Apple"=>"5kg","Banana"=>"7kg","Mango"=>"10kg");
print_r(array_chunk($fruit_weight,2));
?>

Output:

Array ( [0] => Array ( [0] => 5kg [1] => 7kg ) [1] => Array ( [0] => 10kg ) )

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: