Home  >  Article  >  Backend Development  >  如何获取指定时间段的内容,并且对应好其他数组。

如何获取指定时间段的内容,并且对应好其他数组。

WBOY
WBOYOriginal
2016-06-23 14:26:02919browse

$t1=Array ( [0] => 南昌 [1] => 南昌 [2] => 赣州 [3] => 九江 [4] =>赣州  [5] => 九江) 
$t2=Array ( [0] => 2013-09-24 17:48:33  [1] => 2013-09-23 12:48:42  [2] => 2013-09-21 17:48:23  [3] => 2013-09-12 08:40:03  [4] => 2013-09-23 10:28:22  [5] => 2013-09-27 11:28:13 )

比如,我有上面两个数组。$t1【0】和$t2【0】....$t1【i】和$t2【i】是有对应关系的,$t1【0】和$t2【0】代表=====南昌,优秀。

比如,我现在想把$t2数组里面的2013-09-23 10:48:33 至 2013-09-27 11:28:13 之间的数据拿出来,组成一个新的数组,$t22.
然后把$t1里面对应的也匹配上,就是t2里面对应key删除的,t1里面也把对应的key删除。

我想得到的结果是。

$t22=Array ( [0] => 2013-09-24 17:48:33  [1] => 2013-09-23 12:48:42   [2] => 2013-09-27 11:28:13 )
$t11=Array ( [0] => 南昌 [1] => 南昌  [2] => 九江) 
得到这两个新的数组。。求过程。


回复讨论(解决方案)

  function myFunction($v)     {	  $start='2013-09-23 10:48:33';	  $end='2013-09-27 11:28:13';    if ($v>=$start && $v<=$end)        {            return true;        }            return false;    }$t1=Array ( '0' => '南昌' ,'1' => '南昌' ,'2' => '赣州' ,'3' => '九江' ,'4' =>'赣州'  ,'5' => '九江') ;$t2=Array ( '0' => '2013-09-24 17:48:33',  '1' => '2013-09-23 12:48:42' ,'2' => '2013-09-21 17:48:23',  '3' => '2013-09-12 08:40:03',  '4' => '2013-09-23 10:28:22',  '5' => '2013-09-27 11:28:13' );    $t=array_filter($t2,"myFunction");		foreach(array_keys($t) as $k) $t11[]=$t1[$k];	$t22=array_values($t);	print_r($t22);	print_r($t11);

  function myFunction($v)     {	  $start='2013-09-23 10:48:33';	  $end='2013-09-27 11:28:13';    if ($v>=$start && $v<=$end)        {            return true;        }            return false;    }$t1=Array ( '0' => '南昌' ,'1' => '南昌' ,'2' => '赣州' ,'3' => '九江' ,'4' =>'赣州'  ,'5' => '九江') ;$t2=Array ( '0' => '2013-09-24 17:48:33',  '1' => '2013-09-23 12:48:42' ,'2' => '2013-09-21 17:48:23',  '3' => '2013-09-12 08:40:03',  '4' => '2013-09-23 10:28:22',  '5' => '2013-09-27 11:28:13' );    $t=array_filter($t2,"myFunction");		foreach(array_keys($t) as $k) $t11[]=$t1[$k];	$t22=array_values($t);	print_r($t22);	print_r($t11);


高手。。

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