Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to concatenate two array element values in php by special charcter?

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:

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

)
like image 675
nic Avatar asked Dec 01 '22 18:12

nic


1 Answers

Try with array_map like this

$combined = array_map(function($a, $b) { return $a . ' : ' . $b; }, $array1, $array2);
like image 155
Gautam3164 Avatar answered Dec 10 '22 13:12

Gautam3164