PHP array_chunk Function Example

PHP 8 , PHP

Nicesnippets

1269

02-03-2021


Hello Friends,

Now let's see example of how to use array_chunk function in php. This is a short guide on php if array_chunk function. We will use array_chunk function splits an array into chunks of new arrays. Here you will learn how to use array_chunk in php. The last chunk may contain less than size elements. Let's get started with array_chunk function in php.

Here i will give you example of how you can use array_chunk function in php.

Syntax


array_chunk(input_array, size, preserve_keys)

Example

<!DOCTYPE html>

<html>

<head>

<title>PHP array_chunk Function Example - NiceSnippets.com?</title>

</head>

<body>

<?php

$input_array = array('php', 'laravel','java','html');

print_r(array_chunk($input_array,2));

?>

</body>

</html>

Output:

Array ( [0] => Array ( [0] => php [1] => laravel ) [1] => Array ( [0] => java [1] => html ) )

It will help you....


Recommended Posts