Reputation: 3937
How can I properly format or update a date_created
value inside an array so after I will have the same array but with some modified values in it ?
I want to format a date_created
values with this function date("D, d F Y, H:i:s", strtotime($date_created));
Here is the result of dumped array - var_dump($query)
:
array
0 =>
array
'id' => string '2' (length=1)
'title' => string 'Title 2' (length=55)
'date_created' => string '2011-03-09 08:04:14' (length=19)
1 =>
array
'id' => string '1' (length=1)
'title' => string 'Title 2' (length=57)
'date_created' => string '2011-08-14 18:34:04' (length=19)
Upvotes: 0
Views: 157
Reputation: 47956
All you'll have to do is iterate over the array, change the values and replace the sub array with the original in the same index.
foreach($query as $key => $subArray){
$subArray['date_created'] = date("D, d F Y, H:i:s", strtotime($subArray['date_created']));
$query[$key] = $subArray['date_created'];
}
Upvotes: 2