合并两个组数组值到一个数组multidimesional [英] merging two set of array values into one multidimesional array
问题描述
我是在编程和PHP中的新手也和我想知道是否有人能帮助我与我的数组的问题。
我有两个组阵列,例如:
$ NAME =阵列(彼得,彼得,乔);
$汽车=阵列(福特,GMC,慈悲);
和我想将它们合并为一个多维数组这样
$合并=阵列(阵列($名称[0],$汽车[0]),数组($名称[1],$汽车[1]),数组($名称[2],$汽车[2]));
现在,我想保持上述结构的,但我想用本机阵列功能或功能的foreach做到这一点。
我试过 array_merge
和 array_combine
,但它并没有变成为我的预期。结果
我试过 $ ARR3 = $名称+ $汽车;
但它没有工作过。
没有人可以帮助我对我应该使用什么功能?
千恩万谢结果
〜AJI
array_map 听起来就像你在找什么。请参阅示例4创建一个数组的数组
这是有趣的使用这个功能是构造一个数组的数组,可以通过使用NULL作为回调函数的名称
容易进行
块引用>$ =合并array_map(NULL,$名称,$车);
i'm a newbie in programming and in php too and i was wondering if anyone can help me with my array problem.
i have two set of array, example:
$name = array("peter","peter","joe"); $cars = array("ford", "gmc", "mercy");
and i would like to merge them into a multidimensional array like this
$merge = array(array($name[0], $cars[0]),array($name[1], $cars[1]),array($name[2], $cars[2]));
now, i would like keep the structure as above but i would like to do it with a native array function or foreach function.
i've tried
array_merge
andarray_combine
but it didn't turn out as i expected.
i've tried$arr3 = $name + $cars;
but it didn't work toodoes anyone can help me on what function should i use?
many thanks
~aji解决方案array_map sounds like what you are looking for. See "Example #4 Creating an array of arrays"
An interesting use of this function is to construct an array of arrays, which can be easily performed by using NULL as the name of the callback function
$merged = array_map(NULL, $name, $cars);
这篇关于合并两个组数组值到一个数组multidimesional的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!