0
I have a function within a class, and within that function I have the following vector:
$compra = [
"produto" => "Chocolate Nestle",
"preco" => 5.5,
"frete" => 1.5,
"total" => $compra['preco'] + $compra['frete']
];
I need to make the sum of price and freight within the vector itself, I use the var_dump
to show me the result and this error happens:
var_dump($buy);
NOTICE Undefined variable: compra on line number 10
NOTICE Undefined variable: compra on line number 10
array(4) { ["produto"]=> string(16) "Chocolate Nestle" ["preco"]=> float(5.5) ["frete"]=> float(1.5) ["total"]=> int(0) }
line 10 is the line making the sum
It’s possible, but what use is that? Assuming that the "price" and "freight" come from a dynamic variable, you cannot simply add these variables to the "total"?
– ThiagoYou
Have you tried $purchase.price + $purchase.freight ?
– Gunblades