我有 2 个数组,想将它们合并在一起,并且在第二个数组中找不到该项目,插入一个具有空值的键。基本上在array1中添加来自array2的项目,匹配2个array1子键;Array2 不必与数组 1 的长度相同,它的长度总是更小。
数组1
[0][item] = 'aaaa'
[type] = '1234'
[1][item] = 'aaaa'
[type] = '6789'
[2][item] = 'bbbb'
[type] = '1234'
[3][item] = 'bbbb'
[type] = '6789'
和数组2:
[0][item] = 'aaaa'
[type] = '1234'
[feature] = 'www'
[1][item] = 'aaaa'
[type] = '6789'
[feature] = 'www'
结果:
[0][item] = 'aaaa'
[type] = '1234'
[feature] = 'www'
[1][item] = 'aaaa'
[type] = '6789'
[feature] = 'www'
[2][item] = 'bbbb'
[type] = '1234'
[feature] = ''
[3][item] = 'bbbb'
[type] = '6789'
[feature] = ''
我在这里尝试了几个建议,它们都归结为一维数组或匹配索引。有什么建议吗?