我有一个数组$ d的邮政编码,这会生成我的谷歌地图的标记。 我只想显示创建的标记少于3秒,超过3秒将被隐藏。
$postcodes = array();
$diff = array(); // time difference variable
foreach($stmt as $x){
//////////////time calculation start////////////////////////////
$posts[] = $x['date'];
$timePosted = new DateTime($posts[] = $x['date']);
echo 'Time Posted : '. $timePosted ->format("d-m-Y H:i:s");
echo "</br>";
date_default_timezone_set('Europe/London');
$today = date('d-m-Y H:i:s');
echo 'Current time is : '. $today;
echo "</br>";
$today = new DateTime(date('d-m-Y H:i:s'));
$interval = $timePosted->diff($today);
"Difference " . $interval->d. " days ". $interval->h. " hours ".$interval->i." minutes ".$interval->s." seconds ";
echo "</br>";
//$diff[] = $interval->h. " hours ".$interval->i." minutes ".$interval->s." seconds ";
$diff[] = $interval->s; //last array seconds
/////////////////////time calculation finish here/////////////////////////
global $postcodes;
//$postcodes[] = $x['postcode']; //postcodes
foreach ($diff as $time => $seconds) {
echo var_dump($seconds);
if($seconds >=3){
echo "larger than 3 seconds<br />";
}else{
echo "smaller than 3 seconds.<br />";
$postcodes[] = $x['postcode']; //this need to be globle not working yet
}
}//time foreach loop finish here
} /// main foreach loop finish here
$d=' "'.implode('","',$postcodes).'"'; //postcodes inside $postcode array
答案 0 :(得分:0)
我无法相信这有多么简单,事实证明我根本不需要在php中编写这个,我可以在SQL中完成所有我需要的是添加{{1我的sql语句。希望这可以帮助别人。