我有这两个数组,我需要将它们组合起来
Array (
[0] => Column 1
[1] => Column 2
[2] => Column 3
)
Array (
[0] => Array (
[0] => 111
[1] => 222
[2] => 333
)
[1] => Array (
[0] => 444
[1] => 555
[2] => 666
)
)
进入这个
Array (
[0] => Array (
[Column 1] => 111
[Column 2] => 222
[Column 3] => 333
)
[1] => Array (
[Column 1] => 444
[Column 2] => 555
[Column 3] => 666
)
)
这就是我所拥有的并且它有效,但我相信它可以以更简单的方式完成:
$values = array( array( 1,2,3), array( 4,5,6) );
$fields = array( 'Column 1','Column 2','Column 3');
$i = 0;
$j = 0;
$l = 0;
$rows = array();
$columns = array();
foreach($values as $val) {
$rows[] = $val;
foreach ($fields as &$field) {
$columns[$j][$i] = $field;
$i++;
}
$i = 0;
$j++;
}
foreach($columns as $c){
$result[] = array_combine($c,$rows[$l]);
$l++;
}
如果可能的话,我想要清理它。有时我确实遇到了数组问题,而这个数组真的让我很头疼。:-)