2

I divided an array into chunks. I would like to ask how is it possible to loop in them in order to use every chunk as an array and print their data? Here is my code so far..

$chunks = array_chunk($newarray, 5, true);

foreach ($chunks as $index => $chunk) {


}
1
  • 3
    You'll have to be more specific. What do you want to achieve? Don't you just need two nested foreach loops? But what is the use of chunking in the first place then? Also, limit your code to the relevant part, all the xml and curl stuff just distracts. Commented Sep 6, 2017 at 21:25

1 Answer 1

3
$chunks = array_chunk($newarray, 5, true);

for ($i = 0; $i < count($chunks); $i++) {
   for ($n = 0; $n < count($chunks[$i]); $n++) { //or $n = 0; $n < 5; $n++ in your example
      print_r($chunks[$i][$n]);
   }
}

array_chunk() is indexing all chunks by default [0-..to array size]

or with foreach

foreach ($chunks as $index => $chunk)
    foreach ($chunk as $key => $value)
        print_r($index . $key . $value);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.