adding to an assoc array fails after the loop
Posted: Fri Oct 30, 2009 12:23 pm
i am simply trying to dynamically add a new field to an array of nested assoc arrays. When i do the following:
$d["Event"] is uneffected outside of the loop....however, if i do a print_r($d) in the loop, i see the expected addition of the "prettyDate" to the assoc array. Why does it not stay affected after the loop? And how can i remedy that?
Code: Select all
foreach($data as $d)
{
$date = $d['Event']['date'];
$prettyDate = date('M j,Y', strtotime($date));
$d['Event']['prettyDate'] = $prettyDate; //this works and adds to the $d["Event"] assoc array
}
print_r($data); //but after the loop, $d["Event"]["prettyDate"] is not appended...why?