I have the following code:
foreach($this->items as $item) {
echobr("a item price: " . $item->price);
$duplicate = $item;
$duplicate->price = 0;
$duplicate->type = "Discount Item";
echobr("b item price: " . $item->price);
echobr("c dup item price: " . $duplicate->price);
// Duplicate new item to cart
$this->AddItem($duplicate);
}
And the output I get is:
a item price: 10
b item price: 0
c dup item price: 0
So for some reason, changing the price on the temporary variable $duplicate
changes the price on $this-items, but I dont know why? I thought to do that you'd need the use a reference variable, such as &$items
?
$duplicate
is just an alias of$item