hi Guys Good day.. i have this two array that i want to combine:

1st array:

when using print_r($productItems)

Here is the result:

Array
(
    [0] => Array
        (
            [item_id] => 13
            [quantity] => 4
        )

    [1] => Array
        (
            [item_id] => 15
            [quantity] => 1
        )

    [2] => Array
        (
            [pricetotal] => 3709
        )
)

2nd array:

When using print_r($prices)

Here is the result:

Array
(
    [price] => 3,200.00
)

Array
(
    [price] => 509.00
)

By using the array_merge, i came up with a solution:

Here is what i did:

$result = array_merge($productItems, $prices);
print_r($result);

Here is the output:

Array
(
    [0] => Array
        (
            [item_id] => 13
            [quantity] => 4

        )

    [1] => Array
        (
            [item_id] => 15
            [quantity] => 1     


        )

    [2] => Array
        (
            [pricetotal] => 3709
        )

    [price] => 509.00
)

but thats not the result i want to get :

this is my expected output:

Array
(
    [0] => Array
        (
            [item_id] => 13
            [quantity] => 4
        [price] => 3,200.00

        )

    [1] => Array
        (
            [item_id] => 15
            [quantity] => 1
        [price] => 509.00
        )

    [2] => Array
        (
            [pricetotal] => 3709
        )


)

please help me to do this,, im stuck for almost 3 hours already thats why i seek for help. thanks

Provided that $result has one element less than $productItems:

foreach($productItems as $key => $item) {

    if(isset($result[$key])) {

        $productItems[$key]['price'] = $result[$key];
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.