轻量级前端框架助力开发者提升项目效率与性能
601
2022-11-27
thinkphp5 数组报 Illegal string offset 'begin'
先看代码在说话 case1 定义的$time['begin']和$time['end']作为取值数组没问题,奇怪的问题出现在case2中,值是正常取到的,但是赋值到$time['begin']和$time['end']出现了报错 Illegal string offset 'begin' ,一番检查无果,只能把这两个值重新定义为数组,($time1 = strtotime(date("Y-m-d",strtotime("$lastday - 6 days"));$time2 = strtotime($lastday);$time = array(begin =>$time1,end => $time2);)
不知道你们会不会出现这个问题,如果发现我的问题请帮忙指正
switch ($type) { case 1: { // 时间类型日 if(empty($nian) || empty($yue) || empty($ri)){ $now = time(); $nian = date("Y",$now); $yue = date("m",$now); $ri = date("d",$now); } $time['begin'] = mktime(0,0,0,$yue,$ri,$nian); $time['end'] = mktime(23,59,59,($yue+1),$ri,$nian); }; break; case 2: { // 按周统计 if(empty($nian) || empty($yue) || empty($ri)){ $now = time(); $nian = date("Y",$now); $yue = date("m",$now); $ri = date("d",$now); } $time = $nian."/".$yue."/".$ri; $lastday= date("Y-m-d",strtotime("$time Sunday")); $time['begin'] = strtotime(date("Y-m-d",strtotime("$lastday - 6 days"))); $time['end'] = strtotime($lastday);// $time = array(begin =>$time1,end => $time2); }; break; default: { return ''; } }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~