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

php 怎么判断时间连续性

Jun 13, 2016 pm 01:50 PM
arr flag quot strtotime

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

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

PHP code

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

<?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

1

2

3

4

5

6

7

8

9

10

$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
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

How to solve 'undefined: flag.Parse' error in golang? How to solve 'undefined: flag.Parse' error in golang? Jun 24, 2023 pm 10:28 PM

In recent years, Golang, as an emerging programming language, has been favored by many programmers. It is used in network programming, distributed computing, big data processing and other fields. But like any other language, various errors can occur when writing programs in Golang. Among them, the "undefined:flag.Parse" error is a common one. So, how to solve it? First, it is necessary to understand the flag package. The flag package is a Go standard library for parsing command line arguments. it can count

请教怎么修改url某一参数的参数值呢?是要拆开了再拼回去吗 请教怎么修改url某一参数的参数值呢?是要拆开了再拼回去吗 Jun 13, 2016 am 10:24 AM

请问如何修改url某一参数的参数值呢?是要拆开了再拼回去吗?那么请问如何修改url某一参数的参数值呢?是要拆开了再拼回去吗?http://127.0.0.1/myo/newuser.php?mod=search&type=fastone比如现在我要修改mod=new要怎么做呢?------解决方案--------------------发送了请求

Timestamp handling in PHP: How to convert datetime to timestamp using strtotime function Timestamp handling in PHP: How to convert datetime to timestamp using strtotime function Jul 30, 2023 pm 04:19 PM

Timestamp processing in PHP: How to convert datetime to timestamp using strtotime function A timestamp is the number of seconds since January 1, 1970 00:00:00 (GMT) to the present. In PHP, we often need to convert between dates and times, making it easier for us to perform time operations. PHP provides the strtotime function to convert date time into a timestamp. Let's take a look at how to use the strtotime function correctly. First, let's look at

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题 不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题 Jun 13, 2016 am 10:15 AM

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没问题。

图片消失怎么解决 图片消失怎么解决 Apr 07, 2024 pm 03:02 PM

图片消失如何解决先是图片文件上传$file=$_FILES['userfile'];  if(is_uploaded_file($file['tmp_name'])){$query=mysql_query("INSERT INTO gdb_banner(image_src ) VALUES ('images/{$file['name'

Use PHP function 'strtotime' to parse English text date and time into UNIX timestamp Use PHP function 'strtotime' to parse English text date and time into UNIX timestamp Jul 24, 2023 am 09:22 AM

Use the PHP function "strtotime" to parse English text date and time into UNIX timestamps. When developing web applications, we often encounter the need to parse English text date and time. PHP provides a very practical function "strtotime", which can parse date and time strings in various formats into UNIX timestamps. A UNIX timestamp is an integer in seconds, representing the time from January 1, 1970 00:00:00 GMT to the specified date

图片消失怎么解决 图片消失怎么解决 Jun 13, 2016 am 10:09 AM

图片消失如何解决先是图片文件上传$file=$_FILES['userfile'];  if(is_uploaded_file($file['tmp_name'])){$query=mysql_query("INSERT INTO gdb_banner(image_src ) VALUES ('images/{$file['name'

See all articles