Kann mir jemand sagen, warum das $ _SESSION-Array nicht durch den folgenden Code modifiziert wird? Das Objekt soll das Datum in DoNotShipBefore jedes Datensatzes einfügen. Es setzt den Wert offensichtlich irgendwo hin, da die Ausgabe von $ Row ['DoNotShipBefore'] das korrekte Datum anzeigt. Aber wenn die Schleife fertig ist, scheint es nicht zu geschehen.
session_start();
print_r($_SESSION[cart_array]);
foreach($_SESSION[cart_array] as $Row) {
$Row['DoNotShipBefore'] = date("m/d/Y") ;
echo "<br>New Value of DoNotShipBefore (From cart_array): ". $Row['DoNotShipBefore'] ;
}
print "<br><br>";
print_r($_SESSION[cart_array]);
die();
Ausgang folgt:
Array ([0] => Array ([groupId] => 26141 [DoNotShipBefore] => 10/01/2017))
New Value of DoNotShipBefore (From cart_array): 07/06/2017
Array ([0] => Array ([groupId] => 26141 [DoNotShipBefore] => 10/01/2017))
// Should be (or what I want is):
Array ([0] => Array ([groupId] => 26141 [DoNotShipBefore] => 07/06/2017))
Ich habe eine harte Zeit mit meinem Kopf Umwickeln wie Arrays innerhalb der Sitzung zu adressieren, so wirklich jede mögliche Hilfe schätzen würde.
Änderung dieser Zeile 'foreach ($ _ SESSION [cart_array] als $ Row) {' auf 'foreach ($ _ SESSION [cart_array] als & $ Row) {' – cmorrissey
Sie aktualisieren $ nicht _SESSION Array. Aktualisieren Sie nur $ row. –