antjevitsss Posted September 22, 2012 Share Posted September 22, 2012 Hi, this works fine for me too, but how can I return only the next higher number? Like if $actualtime = 16 then I want to return the number 30 and if 31 then 45 and so on. Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/268673-how-to-pick-the-closest-number/ Share on other sites More sharing options...
Barand Posted September 22, 2012 Share Posted September 22, 2012 If there is one thing we love in these forums it's someone saying they have a particular problem (like finding the closest number numerically) and then, when we have given our time to give you a solution, that same someone saying that the actual problem is something different (like finding the nearest number above). In other words, don't waste my time! Link to comment https://forums.phpfreaks.com/topic/268673-how-to-pick-the-closest-number/#findComment-1380087 Share on other sites More sharing options...
premiso Posted September 22, 2012 Share Posted September 22, 2012 Don't necro dead threads. Create your own, this was from 2007... Link to comment https://forums.phpfreaks.com/topic/268673-how-to-pick-the-closest-number/#findComment-1380090 Share on other sites More sharing options...
jcbones Posted September 22, 2012 Share Posted September 22, 2012 Are you sure they are the same person? Try: $numbers = array(0,15,30,45,60); $actual_time = 16; foreach($numbers as $n) { if($n > $actual_time) { $time = $n; break; } } Link to comment https://forums.phpfreaks.com/topic/268673-how-to-pick-the-closest-number/#findComment-1380091 Share on other sites More sharing options...
JLT Posted September 22, 2012 Share Posted September 22, 2012 If there is one thing we love in these forums it's someone saying they have a particular problem (like finding the closest number numerically) and then, when we have given our time to give you a solution, that same someone saying that the actual problem is something different (like finding the nearest number above). In other words, don't waste my time! It was a different someone, wanting a similar thing. Link to comment https://forums.phpfreaks.com/topic/268673-how-to-pick-the-closest-number/#findComment-1380092 Share on other sites More sharing options...
antjevitsss Posted September 22, 2012 Author Share Posted September 22, 2012 Try: Yess, works, thanks! Link to comment https://forums.phpfreaks.com/topic/268673-how-to-pick-the-closest-number/#findComment-1380101 Share on other sites More sharing options...
Philip Posted September 22, 2012 Share Posted September 22, 2012 Went ahead and split this topic (origin) Link to comment https://forums.phpfreaks.com/topic/268673-how-to-pick-the-closest-number/#findComment-1380123 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.