Answers for "breaking long array in php"

PHP
0

breaking long array in php

To reverse an array_chunk, use array_merge, passing the chunks as a variadic:

<?php
$array = [1, 2, 3, 4, 5, 6, 7, 8, 9];

$chunks = array_chunk($array, 3);
// $chunks = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

$de_chunked = array_reduce($array, 'array_merge', []);
// $de_chunked = [1, 2, 3, 4, 5, 6, 7, 8, 9]
?>
Posted by: Guest on August-19-2020

Browse Popular Code Answers by Language