[Solved] Split string into groups of five [closed]


try this

$str = "101,102,103,105,201,250,2564,245564,212,2415,2102,5645,656";

$arr = explode(",", $str);
$arr_chunk = array_chunk($arr, 5);

$arr_output = array();
foreach($arr_chunk as $arr_val)
{
  $arr_output[] = implode(",", $arr_val);
}

print_r($arr_output);

OUTPUT :

Array
(
    [0] => 101,102,103,105,201
    [1] => 250,2564,245564,212,2415
    [2] => 2102,5645,656
)

SEE FIDDLE DEMO

solved Split string into groups of five [closed]