Tuesday, January 24, 2017

How to Generate Dynamic Time Combo

Here is Function will help you to generate a dynamic combo for time


////////////////////////////////


function get_time_combo(){

$rs['0']= '---TIME---';

for($k=0;$k<2;$k++){
for($j=0;$j<12;$j++) {
//$rs[$j][$i]=str_pad($j, 2, "0", STR_PAD_LEFT); 
for($i=0;$i<60;$i++){
if($k==0){
if($j=='00'){
$rs[str_pad(12, 2, "0", STR_PAD_LEFT).":". str_pad($i, 2, "0", STR_PAD_LEFT)." AM"] =str_pad(12, 2, "0", STR_PAD_LEFT).":". str_pad($i, 2, "0", STR_PAD_LEFT)." AM"; 
}else{
$rs[str_pad($j, 2, "0", STR_PAD_LEFT).":". str_pad($i, 2, "0", STR_PAD_LEFT)." AM"] =str_pad($j, 2, "0", STR_PAD_LEFT).":". str_pad($i, 2, "0", STR_PAD_LEFT)." AM"; 
}
}
else {
if($j=='00'){
$rs[str_pad(12, 2, "0", STR_PAD_LEFT).":". str_pad($i, 2, "0", STR_PAD_LEFT)." PM"] =str_pad(12, 2, "0", STR_PAD_LEFT).":". str_pad($i, 2, "0", STR_PAD_LEFT)." PM"; 
}else{
$rs[str_pad($j, 2, "0", STR_PAD_LEFT).":". str_pad($i, 2, "0", STR_PAD_LEFT)." PM"] =str_pad($j, 2, "0", STR_PAD_LEFT).":". str_pad($i, 2, "0", STR_PAD_LEFT)." PM"; 
}
}
}
}
}

return $rs;
}

No comments:

Post a Comment