Forum Moderators: coopster

Message Too Old, No Replies

settype

         

nshack31

7:39 pm on Feb 17, 2006 (gmt 0)

10+ Year Member



the following code will take times such as 5 - 7 and split them into hourly chunks, so 5 - 7 would produce.. 5 - 6 and 6 - 7

$range=split('\s*-\s*', trim($time)); 
$options=array();
settype($range[0], 'float');
settype($range[1], 'float');

for($i=$range[0];$i<$range[1];$i++){

$options[]=$i . ' - ' . ($i+1) ;

}

the problem is that if the time is 4.30 - 6.30 it splits this into 4.3 - 5.3 and 5.3 - 6.3. i need it to produce 4.30 - 5.30. i cant use the integer settype because it then rounds to whole numbers! Can anybody help?

thanks

nshack31

9:39 am on Feb 18, 2006 (gmt 0)

10+ Year Member



bump?! can anybody think of anoher way of doing this?

please help
thanks

coopster

3:17 pm on Feb 18, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Just format it differently ...
for($i=$range[0];$i<$range[1];$i++){ 
//$options[]=$i . ' - ' . ($i+1) ;
$options[] = sprintf [php.net]('%0.2f - %0.2f', $i, $i+1);
}

nshack31

4:54 pm on Feb 18, 2006 (gmt 0)

10+ Year Member



thanks very much :)