2013-08-05 58 views
0

我已經下面如何在特殊字符串中連接兩個數組元素值?

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 

) 

我想連接由以下特殊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 

) 
+0

$ join = array_map(function($ r,$ t){return $ r。 ':'。 $ T; },$ rr,$ tt)); –

回答

8

array_map嘗試這樣

$combined = array_map(function($a, $b) { return $a . ' : ' . $b; }, $array1, $array2)); 
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]); 
} 
0

做到這一點,$combined_array是你的答案wer

$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]; 
} 
相關問題