您可以使用该功能strtotime
,例如:
<?php
$dates = array(
array(
'section' => 'colours',
'dd' => 1,
'mm' => 3,
'yy' => 13,
'name' => 'red',
),
array(
'section' => 'colours',
'dd' => 15,
'mm' => 3,
'yy' => 13,
'name' => 'green',
),
array(
'section' => 'colours',
'dd' => 15,
'mm' => 3,
'yy' => 13,
'name' => 'blue',
),
);
for ($i = 0; $i < count($dates); $i++) {
$dates[$i]['timestamp'] = strtotime('20' . $dates[$i]['yy'] . '-' . $dates[$i]['mm'] . '-' . $dates[$i]['dd']);
}
print_r($dates);
产生输出:
Array
(
[0] => Array
(
[section] => colours
[dd] => 1
[mm] => 3
[yy] => 13
[name] => red
[timestamp] => 1362092400
)
[1] => Array
(
[section] => colours
[dd] => 15
[mm] => 3
[yy] => 13
[name] => green
[timestamp] => 1363302000
)
[2] => Array
(
[section] => colours
[dd] => 15
[mm] => 3
[yy] => 13
[name] => blue
[timestamp] => 1363302000
)
)