Home > Backend Development > PHP Tutorial > php 怎么判断时间连续性

php 怎么判断时间连续性

WBOY
Release: 2016-06-13 10:03:13
Original
1777 people have browsed it

php 如何判断时间连续性?
$time = array('2011-10-25','2011-10-27','2011-11-01');等等,如何判断时间是否是连续的?

------解决方案--------------------
strtotime('2011-10-25');后判断。
------解决方案--------------------
mktime() strtotime date 这三个函数就可以做到 自己研究去吧
------解决方案--------------------
相邻2个转换成时间戳相减是否为一天的时间戳(如果一天算连续的话)
------解决方案--------------------
整个数组时间连续还是部分连续?
整个数组连续的:

PHP code
<?php $arr = array('2011-10-25','2011-10-27','2011-10-26','2011-10-24');function compare($x,$y){ return (strtotime($x)-strtotime($y));}uasort($arr,'compare');$arr = array_slice($arr,0);for($i = 1;$i<count($arr);$i++){   if((strtotime($arr[$i])-strtotime($arr[0]))==($i*24*60*60)){     $flag = 1;   }   else{     $flag = 0;     break;   }}echo $flag?"连续":"不连续";<br /><font color="#e78608">------解决方案--------------------</font><br>刚才在另一个帖子 贴出了我的方法<br>是以时间递增一天算得:<br>
Copy after login
PHP code
$a = array('2011-10-30','2011-10-31','2011-11-01');$flag = true;for($i=0;$i<count date day if false break echo class="clear">
                 
              
              
        
            </count>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template