I am having trouble assigning a variable to an array within the $_SESSION
array.
It looks like it is assigning, but when I do a print_r at the end of the program the $_SESSION
variable appears unchanged.
Here is the code.
<?php
session_start();
print_r($_SESSION[cart_array]);
$NewGroupName="NewGroupName";
foreach($_SESSION[cart_array] as $row) {
if ($row['groupId'] == "26141"){
echo "The initial GroupName is" . $row['GroupName'] . "<br>";
echo "The GroupName should be " . $NewGroupName."<br>";
$row['GroupName'] = $NewGroupName;
echo "The actual GroupName is " . $row['GroupName']."<br>";
}
}
print_r($_SESSION[cart_array]);
?>
The first print_r
:
Array ( [0] => Array ( [groupId] => 26141 [GroupName] => 'Crystal Farm - Ten Yard Case Pack' [StylePatternColor] => A-CF-10 [Price] => 5.65 [StandardPutUp] => 320 [Discount] => 0 [DiscountText] => [StkUnit] => YDS [ListPrice] => 5.65 [Quantity] => 1 [PromiseDate] => 10/01/2017 [DoNotShipBefore] => 02-01-2017 [ColorName] => 32 Ten Yard Bolts [PatternName] => [SKUDescription] => [KitPerYardDiscount] => False [KitPerYardDiscountText] => False [Kit] => False ) [] => Array ( [DoNotShipBefore] => ) )
The assingment seems to work:
The initial GroupName is'Crystal Farm - Ten Yard Case Pack'
The GroupName should be NewGroupName
The actual GroupName is NewGroupName
But, the final print_r shows we have not changed the value of GroupName.
Array ( [0] => Array ( [groupId] => 26141 [GroupName]
=> 'Crystal Farm - Ten Yard Case Pack' [StylePatternColor]
=> A-CF-10 [Price]
=> 5.65 [StandardPutUp]
=> 320 [Discount]
=> 0 [DiscountText]
=> [StkUnit]
=> YDS [ListPrice]
=> 5.65 [Quantity]
=> 1 [PromiseDate]
=> 10/01/2017 [DoNotShipBefore] => 02-01-2017 [ColorName]
=> 32 Ten Yard Bolts [PatternName] => [SKUDescription] => [KitPerYardDiscount] => False [KitPerYardDiscountText] => False [Kit] => False ) []
=> Array ( [DoNotShipBefore] => ) )
Any help would be appreciated.