如何将两个数组的字符串值与PHP成对连接? [英] how do I concatenate the string values of two arrays pairwise with PHP?

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

问题描述

所以我有两个数组

Array
(
[0] => test
[1] => test 1
[2] => test 2
[3] => test 3
)

Array
(
[0] => test
[1] => test 1
[2] => test 2
[3] => test 3
)

我想将它们组合在一起,以获得这样的数组?

I want to combine them together so I get an array like this?

Array
(
[0] => test test
[1] => test 1 test 1
[2] => test 2 test 2
[3] => test 3 test 3
)

我发现了很多功能,例如array_mergearray_combine,但是没有什么可以做的.

I have found lots of functions like array_merge and array_combine but nothing that does what I want to do.

有什么想法吗?

谢谢.

最大

推荐答案

您可以使用array_map做到这一点:

You could do it with array_map:

$combined = array_map(function($a, $b) { return $a . ' ' . $b; }, $a1, $a2));

这篇关于如何将两个数组的字符串值与PHP成对连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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