我有3个数组叫做player1,player2,score:
Array ( [0] => player1 [1] => player1 [2] => player1 )
Array ( [0] => player2 [1] => player3 [2] => player2 )
Array ( [0] => 2-3 [1] => 1-3 [2] => 2-0 )我需要的是像这样连接所有数组
[0] => player1, player2, 2-3
[1] => player1, player3, 1-3
[2] => player1, player2, 2-0我是PHP的新手,在发帖前我使用了搜索栏。请不要投反对票。
发布于 2013-03-05 20:14:06
试试这个:
array_unshift($array, null);
$res = call_user_func_array('array_map', $array);
echo "<pre>";
print_r($res);编辑: 10now的评论
$res = array_map(null, $player1, $player2, $score);
echo "<pre>";
print_r($res);发布于 2013-03-05 20:21:50
$array1 = array ( 'player1', 'player1', 'player1' );
$array2 = array ( 'player2', 'player3', 'player2' ) ;
$array3 = array ( '2-3', '1-3', '2-0' );
$mi = new MultipleIterator();
$mi->attachIterator(new ArrayIterator($array1));
$mi->attachIterator(new ArrayIterator($array2));
$mi->attachIterator(new ArrayIterator($array3));
$newArray = array();
foreach ( $mi as $value ) {
$newArray[] = $value;
list($team1, $team2, $result) = $value;
echo $team1 , ' v ' , $team2, ' -> ', $result , '<br />';
}
var_dump($newArray);发布于 2013-03-05 20:13:36
$x=0;
foreach($arr1 as &$e){
$e.=", $arr2[$x], $arr3[$x]";
$x++;
}这应该会使第一个数组成为所需的结果。
https://stackoverflow.com/questions/15223428
复制相似问题