I'm trying to run a clean up job on data in an array, specifically converting epoch time to YYYY-MM-DD.
I tried this function originally:
foreach ($data as $row) {
$row['eventdate'] = date('Y-m-d', $row['eventdate']);
}
echo '<pre>';
print_r($data);
echo '</pre>';
However the foreach loop didn't update the data when I output it.
The following for loop did work:
for ($i=0; $i<count($data); $i++) {
$data[$i]['eventdate'] = date('Y-m-d', $data[$i]['eventdate']);
}
Why did the first loop fail and the second work? Aren't they the same?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…