0

我有 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 很陌生,我在发布之前使用了搜索栏。请不要投反对票。

4

3 回答 3

1

试试这个 :

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-05T12:14:06.393 回答
1
$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-05T12:21:49.523 回答
0
$x=0;
foreach($arr1 as &$e){
    $e.=", $arr2[$x], $arr3[$x]";
    $x++;
}

这应该将第一个数组保留为所需的结果。

于 2013-03-05T12:13:36.060 回答