2

私が欲しいのは、(ループefficientせずに)配列をマージする方法です。 first element of the resulting arrayfirst element of the first arraythe second element of the resulting arraythe second element of the second array

例:

$arr1 = array(1, 3, 5);
$arr2 = array(2, 4, 6);

$resultingArray = array(1, 2, 3, 4, 5, 6);
4

2 に答える 2

1

この「ハック」を本当に推奨するわけではありませんが、これで十分です。

$result = array();
array_map(function ($a, $b) use (&$result) { array_push($result, $a, $b); }, $arr1, $arr2);

それは本当に二重ループを背後に隠しているだけなarray_mapので、まあ...

于 2013-07-14T11:42:56.010 に答える