<?php
$date = '2016-5-31';
$time = '13:00';
$large = date('H:i',strtotime('+30 minute',strtotime($time)));
$little = date('H:i',strtotime('-30 minute',strtotime($time)));
function getmapp($large,$little){
$data = array(
'0'=>array(
'time'=>'06:10',
'code'=>'1111'
),
'1'=>array(
'time'=>'07:10',
'code'=>'2222'
),
'2'=>array(
'time'=>'08:10',
'code'=>'3333'
),
'3'=>array(
'time'=>'09:10',
'code'=>'4444'
),
'4'=>array(
'time'=>'10:10',
'code'=>'5555'
),
'5'=>array(
'time'=>'11:10',
'code'=>'6666'
),
'6'=>array(
'time'=>'12:30',
'code'=>'7777'
),
'7'=>array(
'time'=>'13:50',
'code'=>'8888'
),
'8'=>array(
'time'=>'15:10',
'code'=>'9999'
),
'9'=>array(
'time'=>'16:10',
'code'=>'1010'
),
);
foreach ($data as $k => $v) {
if($v['time'] >= $little && $v['time'] <= $large ){
$the_ticket = $v;
$info['large'] =$large;
$info['little'] =$little;
$info['ticket'] =$the_ticket;
return $info; //符合提交.返回30分钟内的车票
}
}
$large = date('H:i',strtotime('+30 minute',strtotime($large)));
$little = date('H:i',strtotime('-30 minute',strtotime($little)));
return getmapp($large,$little); //30分内没有车票.再递归调用.返回结果到这里..需要再次返回给外部
}
$ti = getmapp($large, $little);
echo '<meta http-equiv="Content-type" content="text/html:charset=utf-8">';
echo '<pre>';
var_dump($ti);