如何将3个数组合并为一个大数组(相同的键) [英] How to merge 3 arrays into one big array (same keys)

查看:641
本文介绍了如何将3个数组合并为一个大数组(相同的键)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个数组,分别称为player1,player2,得分:

I have 3 arrays called 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 )

我需要加入所有这样的数组

What I need is to join all arrays like this

[0] => player1, player2, 2-3
[1] => player1, player3, 1-3
[2] => player1, player2, 2-0

我对PHP很陌生,在发布之前我使用了搜索栏。

I am pretty new to PHP and I used the search bar before posting. Please do not down vote.

推荐答案

请尝试以下操作:

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);

这篇关于如何将3个数组合并为一个大数组(相同的键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆