如何将两个数组合并为键/ val [英] How to merge two arrays as key/val
本文介绍了如何将两个数组合并为键/ val的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将两个数组合并为键/值对?
How can you merge two arrays into key/value pairs please?
从此......
array1 = ['test1', 'test2'];
array2 = ['1', '2'];
到此......
array3 = ['test1':'1', 'test2':'2'];
推荐答案
参见 http://phpjs.org/functions/array_combine:307
编辑:再看一下你的问题,你可能会更喜欢这样的事情:
Looking at your question again, you might be after something more like this:
function mergeArrays(arr1, arr2) {
var l = Math.min(arr1.length,arr2.length),
ret = [],
i;
for( i=0; i<l; i++) {
ret.push(arr1[i]+":"+arr2[i]);
}
return ret;
}
这篇关于如何将两个数组合并为键/ val的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文