'I want to store data in new index as per my key in php [duplicate]

I am having a data in array format with key and value what I want is from first key 0 to key 6 data I want to store in a new array with index 0 same for every other key 7 to 13 key with 1 index in new array in PHP

enter image description here



Solution 1:[1]

First, as suggested above, do not upload image of your code, just paste it here.

Just use PHP array_chunk function:

$pieces = array_chunk($my_array, 6);

Solution 2:[2]

you can use array_chunk() function

<?php
$a = ["a","a","a","a","a","a","a","a"];

$b = array_chunk($a, 7);

echo"<pre>";print_r($b);

?>

output be like:

Array
(
    [0] => Array
        (
            [0] => a
            [1] => a
            [2] => a
            [3] => a
            [4] => a
            [5] => a
            [6] => a
        )

    [1] => Array
        (
            [0] => a
        )

)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Luca Murante
Solution 2 sivan