1
I have an array in a $_SESSION['Carrinho']
:
Array ( [0] => Array ( [Produto] => ENH1264-1
[Quantidade] => 2 )
[1] => Array ( [Produto] => ENH1264-2
[Quantidade] => 3 )
[2] => Array ( [Produto] => ENH1264-6
[Quantidade] => 1 )
)
I would like to add new values to this array. I have this second array:
Array ( [0] => Array ( [Produto] => ENH1264-6
[Quantidade] => 5 )
[1] => Array ( [Produto] => ENH1264-1
[Quantidade] => 8 )
)
Is there any way, without going out doing several foreach comparing the results, generating new arrays? Some simplified way?
The expected result would be:
Array (
[0] => Array (
[Produto] => ENH1264-1
[Quantidade] => 10
)
[1] => Array (
[Produto] => ENH1264-2
[Quantidade] => 3
)
[2] => Array (
[Produto] => ENH1264-6
[Quantidade] => 6
)
)
see that the products that are equal had their quantities added up. If in the second array there is a product you do not have in the first, add as new index.
What is the expected result? You can ask the question?
– Woss
@Andersoncarloswoss made!
– Maykel Esser
So what you want is not to add elements with equal indexes, as the title says, but to add the items of the same name in
Produto
?– Woss
would be just that! If you have the same value in the index "product", add the Index "quantity"!
– Maykel Esser