从数组中创建内部字符串的相等部分

Lets say I have a array of 120 items. I need to separate them into comma separated texts in equal chunks.

For example if I choose to separate all elements to chunks of 50 / 120 items should be separated as 50, 50 and 20.

I tried below code:

$lines = file("all.txt", FILE_IGNORE_NEW_LINES);
$allarr[] = array_chunk($lines, 50);


foreach($allarr[0]  as $chunks);
{
    $str = implode($chunks,",");

    echo $str."<br><br>";
 }

The above code create the correct chunks of array. But When I want to loop it and add implode. It just prints the last array.

EDIT : For easy understanding below is the example

$lines = array(1,2,3,4,5);
$allarr = array_chunk($lines, 3);
var_dump($allar);

foreach($allarr as $chunks);
{

var_dump($chunks);
$str = implode($chunks,",");

}

Where $allar output is

array(2) {
  [0]=>
  array(3) {
    [0]=>
    int(1)
    [1]=>
    int(2)
    [2]=>
    int(3)
  }
  [1]=>
  array(2) {
    [0]=>
    int(4)
    [1]=>
    int(5)
  }
}

But $chunks output is only last part of array

array(2) {
  [0]=>
  int(4)
  [1]=>
  int(5)
}

You have an extra ; that's ending the foreach loop early.

foreach ($allarr as $chunks);
                            ^

So you're doing nothing in the foreach loop, and then doing var_dump($chunks) after the loop is finished. That's why it only shows the last chunk.

Get rid of that ; and it will work correctly.

DEMO