伊谢尔伦2017-04-10 17:46:40
你的意思是让$array_1变成
$array_1 = array{
'one' => array('1','2','3','10'),
'two' => array('4','5','6'),
'three' => array('7','8','9')
};
?
PHP中文网2017-04-10 17:46:40
$j = 0;
$array_3 = $array_1;
for($i=0;$i<count($array_2);$i++){
$array_1[$array_3[$j]][] = $array_2[$i];
if (!(($i+1)%3))
$j++;
}
迷茫2017-04-10 17:46:40
<?php
$array_1 = ["one", "two", "three"];
$array_2 = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"];
$tmp = array();
for($i = 0, $j = 0; $i < count($array_2); $i++) {
if($i % 3 == 0 && $i != 0) $j++;
if(count($array_1) == $j) $j = 0;
$tmp[$array_1[$j]][] = $array_2[$i];
}