Home  >  Article  >  Backend Development  >  strtotime 对待数组怎么处理

strtotime 对待数组怎么处理

WBOY
WBOYOriginal
2016-06-13 12:49:27751browse

strtotime 对待数组怎么办?
是这样的,一个表单的提交,要把日期格式的时间,换为时间戳,以前都是直接使用strtotime 解决,但是因为表单需要根据需要点击增加行,现在把所有的字段都变成了数组,例如:

<td><input type="text" name="date[]" style="width:100px;font-size: 12px; text-align:center" class="Wdate" onFocus="WdatePicker({isShowClear:false,readOnly:true,skin:'whyGreen',minDate:'%y-%M-{%d}',doubleCalendar:true,dateFmt:'yyyy-MM-dd'})"></td>


用的是一个JS 的插件,直接选取时间的,  以前不用数组的方式,为:
<td><input type="text" name="cfriqi" style="width:100px;font-size: 12px; text-align:center" class="Wdate" onFocus="WdatePicker({isShowClear:false,readOnly:true,skin:'whyGreen',minDate:'%y-%M-{%d}',doubleCalendar:true,dateFmt:'yyyy-MM-dd'})"></td>


就是在字段 date 后面加上[], 变成了date[] 了,这样就是按照数组post,
处理页面,如果不是数组,直接
$date =strtotime($_post[date]) 

就可以直接转成时间戳了,但是现在变成了数组,如果直接使用:
$date_arr =strtotime($_post[date]) 

就会报错,插入不了数据库,请问怎么解决呢?

时间戳 strtotime 数组
------解决方案--------------------
$date_arr = array_map('strtotime', $_POST['date']); 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn