随手写的一些好用的功能(不定时更新)

来源:互联网 发布:origin9.1绘图软件 编辑:程序博客网 时间:2024/05/17 12:25

1.整理多表单传送值问题

当遇到前台同名表单以数组形式传递过来的数值时,为了分组规范,必须要整理,所以就有了下面的功能

假设: $data_temp = $_POST;(当然实际情况不一定直接这样接收,可能涉及到需要特殊字符过滤)

 foreach($data_temp as $key=>$val){
            foreach($val as $ek=>$evl){
$data[$ek][$key] = $evl;
            }
        }

2.自定义递归翻转数组

 function array_rev($arr){
      for($i=count($arr)-1;$i>=0;$i--){
          if(is_array($arr[$i])){   //这里判断是否为数组
              $temp1 = array_rev($arr[$i]);  //若为数组则开始调用自身
              $temp[] = $temp1;
              continue;
          }
          $temp[] = $arr[$i];
      }
      return $temp;
  }

//昨天,今天和明天的日期转换//($startstr 今天开始时间戳)//返回(昨天,今天和明天)的0点和23点59分59秒function alldaytostr($startstr) {    $oneday_count = 3600 * 24;  //一天有多少秒    //明天    $tomorrow_s = $startstr + $oneday_count;    //明天开始    $tomorrow_e = $tomorrow_s + $oneday_count - 1;  //明天结束    //昨天    $yesterday_s = $startstr - $oneday_count;  //昨天开始    $yesterday_e = $startstr - 1;   //昨天结束    //今天结束    $today_e = $tomorrow_s - 1;    //昨天、今天和明天 0点和当天23点59分59秒合并成数组    $allday_array = array('yesterday' => array($yesterday_s, $yesterday_e),        'today' => array($startstr, $today_e),        'tomorrow' => array($tomorrow_s, $tomorrow_e));    return $allday_array;}
定义一个开始时间和结束时间,判断比较如果这两个时间之间相差大于3天则用结束时间减去开始时间然后所得时间差除以2取得中间时间,若两时间差小于3天则直接返回开始时间。
function apart($start_time,$end_time){$start_time = strtotime(date('Y-m-d',$start_time));$end_time = strtotime(date('Y-m-d',$end_time)); $apart_time = $end_time - $start_time; $day = $apart_time / 86400; if($day <= 3){ $time = date('Y-m-d',$start_time); }else{ $space = ceil($day / 2); $time = date("Y-m-d",strtotime($space.' days',$start_time)); }return $time;}



1 0