我想爆炸一个日期,但想分别将默认索引0,1,2重命名为年,月,日,我试过,但我无法弄明白.这就是现在正在做的事情.
$explode_date = explode("-", "2012-09-28");
echo $explode_date[0]; //Output is 2012
echo $explode_date[1]; //Output is 09
echo $explode_date[2]; //Output is 28
Run Code Online (Sandbox Code Playgroud)
我想要的是
echo $explode_date['year']; //Output is 2012
echo $explode_date['month']; //Output is 09
echo $explode_date['day']; //Output is 28
Run Code Online (Sandbox Code Playgroud)
谢谢..
list($date['year'], $date['month'], $date['day']) = explode('-', '2012-09-28');
Run Code Online (Sandbox Code Playgroud)
$keys = array('year', 'month', 'day');
$values = explode("-", "2012-09-28");
$dates = array_combine($keys, $values);
Run Code Online (Sandbox Code Playgroud)