what is the difference between
$totalprice += $product['price'] * $product['count'];
and
$totalprice = $product['price'] * $product['count'];
both give the same result. so what's the use of (+=) ?
+=
is a shorthand for adding the result to the target. The first one is equivalent to:
$totalprice = $totalprice + ($product['price'] * $product['count']);
There are also other compound operators -=
, *=
, /=
, etc.