i have two arrays given below
我有两个阵列如下
Array
(
[0] => 2013-07-09
[1] => 2013-07-16
[2] => 2013-07-23
[3] => 2013-07-30
)
Array
(
[0] => 2013-07-16
[1] => 2013-07-23
[2] => 2013-07-30
[3] => 2013-08-06
)
i want to concatenate two array element values by special character.given output below:
我想通过下面的特殊character.given输出连接两个数组元素值:
Array
(
[0] => 2013-07-09 : 2013-07-16
[1] => 2013-07-16 : 2013-07-23
[2] => 2013-07-23 : 2013-08-30
[3] => 2013-08-30 : 2013-08-06
)
3 个解决方案
#1
8
Try with array_map
like this
尝试使用这样的array_map
$combined = array_map(function($a, $b) { return $a . ' : ' . $b; }, $array1, $array2));
#2
0
$a1 = new ArrayIterator($array1);
$a2 = new ArrayIterator($array2);
$it = new MultipleIterator;
$it->attachIterator($a1);
$it->attachIterator($a2);
foreach($it as $e) {
$array3[] = $e[0]." : ".$e[1]);
}
#3
0
do this , $combined_array
is your answer
这样做,$ combined_array就是你的答案
$array1 = Array
(
[0] => 2013-07-09
[1] => 2013-07-16
[2] => 2013-07-23
[3] => 2013-07-30
);
$array2 = Array
(
[0] => 2013-07-16
[1] => 2013-07-23
[2] => 2013-07-30
[3] => 2013-08-06
);
$combined_array = array();
foreach($array1 as $key=>$value)
{
$combined_array[$key]=$value." : ".$array2[$key];
}
#1
8
Try with array_map
like this
尝试使用这样的array_map
$combined = array_map(function($a, $b) { return $a . ' : ' . $b; }, $array1, $array2));
#2
0
$a1 = new ArrayIterator($array1);
$a2 = new ArrayIterator($array2);
$it = new MultipleIterator;
$it->attachIterator($a1);
$it->attachIterator($a2);
foreach($it as $e) {
$array3[] = $e[0]." : ".$e[1]);
}
#3
0
do this , $combined_array
is your answer
这样做,$ combined_array就是你的答案
$array1 = Array
(
[0] => 2013-07-09
[1] => 2013-07-16
[2] => 2013-07-23
[3] => 2013-07-30
);
$array2 = Array
(
[0] => 2013-07-16
[1] => 2013-07-23
[2] => 2013-07-30
[3] => 2013-08-06
);
$combined_array = array();
foreach($array1 as $key=>$value)
{
$combined_array[$key]=$value." : ".$array2[$key];
}