PHP | array_chunk() Function


The array_chunk() function is an inbuilt function in PHP which is used to split an array into parts or chunks of given size depending upon the parameters passed to the function. The last chunk may contain fewer elements than the desired size of the chunk.

Syntax:

array array_chunk( $array, $size, $preserve_keys )

Parameters: This function accepts three parameters as shown in the above syntax. The parameters are described below:

  • $array: This parameter represents the array that is needed to be divided into chunks.
  • $size: This parameter is an integer which defines the size of the chunks to be created.
  • $preserve_keys: This parameter takes Boolean value. When this parameter is set to TRUE then the keys are preserved, otherwise the chunk is reindexed starting from 0.


Jay Kakadiya

Jay Kakadiya Creator

I am a computer field, & i am Web developer.

Suggested Creators

Jay Kakadiya