X
X
XenK2016-08-12 06:16:44
PHP
XenK, 2016-08-12 06:16:44

Merge two arrays?

There is the first array:

Array
(
    [0] => Array
        (
            [date_sum] => 11.08.2016
            [money] => 1234
        )

    [1] => Array
        (
            [date_sum] => 10.08.2016
            [money] => 5555
        )
...

And there is a second array:
Array
(
    [0] => Array
        (
            [status] => 1
        )

    [1] => Array
        (
            [status] => 0
        )

What is the right way to merge these two arrays so that it looks like this:
Array
(
    [0] => Array
        (
            [date_sum] => 11.08.2016
            [money] => 1234
            [status] => 1
        )

    [1] => Array
        (
            [date_sum] => 10.08.2016
            [money] => 5555
            [status] => 0
        )
...

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
DevMan, 2016-08-12
@XenK

https://gist.github.com/ptz0n/1646171#file-gistfil...

M
Maxim Zavitaev, 2016-08-12
@vsk_web

write a for loop. Take each element and push one to the other

S
Stanislav, 2016-08-12
@Stasgar

$res3=[];
array_push($res3,array_merge($arr1[0],$arr2[0]),array_merge($arr1[1],$arr2[1]));

print_r($res3);

P
PooH63, 2016-08-12
@PooH63

for ($i = 0; $i <= count($a); $i++) {
    if(!empty($b[$i])) {
        $res[] = array_merge($a[$i], $b[$i]);
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question