PHP array_chunk() is an inbuilt function that splits the array into chunks of new arrays. The array_chunk() returns the multidimensional indexed array, starting with index zero, with each dimension containing size elements. I am using PHP version 7.2.14 for this example. The last chunk may contain less than size elements.

PHP array_chunk example

The syntax of array_chunk() function is following.

array_chunk(array,size,preserve_key);

An array parameter is required which specifies an array to use.

The size parameter is required which is an integer that specifies the size of the chunk.

The preserve_key parameter is optional. Possible values.

  1. true – Preserves the keys.
  2. false – Default. Reindexes the chunk numerically.

#php #php array_chunk

PHP array_chunk Example | array_chunk Function Tutorial
1.40 GEEK