我有这个数组;
Array
(
[2017-04-01] => 0
[2017-04-02] => 0
[2017-04-03] => 0
[2017-04-04] => 0
[2017-04-05] => 0
)
如何将日期格式化为这样的内容?
Array
(
[01-04-2017] => 0
[02-04-2017] => 0
[03-04-2017] => 0
[04-04-2017] => 0
[05-04-2017] => 0
)
谢谢。
一个简单的
foreach
循环然后转换为格式d-m-Y
可以做到这一点
$result = [];
foreach ($datas as $key => $value) {
$date = date('d-m-Y', strtotime($key));
$result[$date] = $value;
}
print_r($result);