[英]Modify key values in multi-dimensional array
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 ? 如何正确地格式化或更新数组中的date_created
值,以便在我将拥有相同的数组但其中包含一些修改后的值之后?
I want to format a date_created
values with this function date("D, d FY, H:i:s", strtotime($date_created));
我想用这个函数date("D, d FY, H:i:s", strtotime($date_created));
格式化date_created
值date("D, d FY, H:i:s", strtotime($date_created));
Here is the result of dumped array - var_dump($query)
: 这是dumped数组的结果 - 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)
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'];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.