尝试这个 :
$var = array(0=> "test1",1=> "test2");
$vals = array(0 => 351,1 => 352,2 => 353,3 => 354,4 => 355,5 => 356);
$res = array_combine($var,array_map('implode', array_fill(0, count(array_chunk($vals,3)), ','), array_chunk($vals,3)));
echo "<pre>";
print_r($res);
输出 :
Array
(
[test1] => 351,352,353
[test2] => 354,355,356
)
编辑:根据评论“这种类型的输出我需要数组([0] => 351,352,353 [1] => 354,355,356) “
$vals = array(0 => 351,1 => 352,2 => 353,3 => 354,4 => 355,5 => 356);
$res = array_map('implode', array_fill(0, count(array_chunk($vals,3)), ','), array_chunk($vals,3));
echo "<pre>";
print_r($res);
输出:
Array
(
[0] => 351,352,353
[1] => 354,355,356
)