如何组合两个数组? [英] How can you combine two arrays?

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

问题描述

它们被简化如下,足以解决这个问题.这个问题基于 这个答案.

They are simplified as follows which is enough for this question. This question is based on this answer.

[a][b][]

[a][c]

其中两个数组都有一个公共子数组 [a].

where both arrays has one common subarray [a].

我想要这个

[a][c][b][]

我没有成功运行以下命令

I have run the following command unsuccessfully

array1[a] + array2[a]

推荐答案

foreach($array1 as $a => $c)
{
    $end_array[$c] = $array2[$a];
}

<小时>

// For every [a]
foreach($array1 as $a => $c)
{
    // Get the [b]
    $b = $array2[$a];

    // Add it to [a][c]
    $end_array[$a][$c] = $b;

    // Making it $end_array[$a][$c][$b] = array(....);
}

这篇关于如何组合两个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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