0

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

sivan
  • 57
  • 8
Gautam
  • 1
  • 2

2 Answers2

0

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);
Luca Murante
  • 317
  • 3
  • 8
  • [The fundamental goal of closing duplicate questions is to help people find the right answer by getting all of those answers in one place.](https://stackoverflow.com/help/duplicates#:~:text=The%20fundamental%20goal%20of%20closing%20duplicate%20questions%20is%20to%20help%20people%20find%20the%20right%20answer%20by%20getting%20all%20of%20those%20answers%20in%20one%20place.) – mickmackusa May 14 '22 at 09:18
0

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
        )

)
sivan
  • 57
  • 8
  • [The fundamental goal of closing duplicate questions is to help people find the right answer by getting all of those answers in one place.](https://stackoverflow.com/help/duplicates#:~:text=The%20fundamental%20goal%20of%20closing%20duplicate%20questions%20is%20to%20help%20people%20find%20the%20right%20answer%20by%20getting%20all%20of%20those%20answers%20in%20one%20place.) – mickmackusa May 14 '22 at 09:18