简体   繁体   English

用于在数组中查找匹配索引字符串的PHP函数?

[英]PHP function for concating matching index strings in array?

Alright, I know it can be done like so... 好吧,我知道可以这样做......

$Array1 = array("Hello, ", "foo", "The quick brown fox jumped ");
$Array2 = array("World!", "bar", "the lazy dog.");
$Array3 = array();
for($x = 0; $x < count($Array1); $x++) {
    $Array3[] = $Array1[$x] . $Array2[$x];
}
// returns this -> ("Hello, World", "foobar", "The quick brown fox jumped over the lazy dog.")

But is there a native PHP function for this? 但是有一个原生的PHP函数吗? Like this: 像这样:

$Array3 = array_concat_strings($Array1, $Array2)

I searched through php.net, and didn't find anything, but I like to be sure I'm not missing something. 我通过php.net搜索,但没有找到任何东西,但我想确定我没有遗漏任何东西。

我不认为有这样一个特殊的本机功能,但你可以自己做:

$array3 = array_map(function ($a, $b) { return $a . $b; }, $array1, $array2);

对不起,没有这样的功能

There is no such native function, but you can do it without the third array, for example 没有这样的本机功能,但是你可以在没有第三个数组的情况下完成它

foreach($Array1 as $key=>$value)
  $Array1[$key] .= $Array2[$key];

print_r($Array1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM