'array merge php with same index

I have this situation:

$qty = array(1) {[0]=> array(1) { ["qty"]=> string(5) "35254" }
$price = array(1) {[0]=> array(1) { ["price"]=> string(5) "1000" }

How can I get this?

$res = array(1) {[0]=> array(1) { ["qty"]=> string(5) "35254" ["price"]=> string(5) "1000"}

Thanks for the answers



Solution 1:[1]

$qty = array("qty"=>"35254" );
$price = array ( "price"=> "1000" );

$combine = array_merge($qty,$price);
var_dump($combine);

Solution 2:[2]

try with

$res = array_merge_recursive($qty, $price);
print_r($res);

Solution 3:[3]

Not as pretty but with the same result.

$result = array_map(function ($e1,$e2) {
    return array_merge_recursive($e1, $e2);
}, $qty,$price);

$result =
    array(1) {
      [0]=>
      array(2) {
        ["qty"]=>
        string(5) "35254"
        ["price"]=>
        string(4) "1000"
      }
    }

and for indexed arrays

$a = ['a', 'b', 'c'];
$n = [1, 2, 3];

$result = array_map(function ($e1,$e2) {
    return [$e1, $e2];
}, $a,$n);

$result = [
 0 => ['a', 1],
 1 => ['b', 2],
 2 => ['c', 3]
];

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris
Solution 2 Ram Sharma
Solution 3