severndigital Posted December 22, 2007 Share Posted December 22, 2007 I'm not sure how to title this post. But this is what i want to do. I need to take two variable numbers say 75 and 30000. Then I need to step out the difference over a variable amount of cells. in this case say 20 cells. the output should look something like this. 75 80 93 123 178 320 ... ... ... 30000 I'm not even really sure where to start other than the incoming variables. thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/82819-expanding-numbers/ Share on other sites More sharing options...
Orio Posted December 22, 2007 Share Posted December 22, 2007 I can't see the pattern in here: 75 80 93 123 178 320 ... ... ... 30000 How do you want to get 80,93,123... ? Orio. Quote Link to comment https://forums.phpfreaks.com/topic/82819-expanding-numbers/#findComment-421186 Share on other sites More sharing options...
severndigital Posted December 22, 2007 Author Share Posted December 22, 2007 there is no pattern .. at least in my example. all i want to do is input the following $start = 75; $end = 30000; $steps = 20; I want the code to get from 75 to 30000 in 20 steps. whatever the numbers may be. The more I work on this, I think I will have to also input a rate or some sort of min / max for each cell increase. for example $minrate = 3; $maxrate = 500; this would state that when stepping out the numbers the current number cannot be less than 3 percent of the next number and no more than 500 percent of the preceeding number. Quote Link to comment https://forums.phpfreaks.com/topic/82819-expanding-numbers/#findComment-421188 Share on other sites More sharing options...
Orio Posted December 22, 2007 Share Posted December 22, 2007 If you are using PHP5, you can simply use range() with the $step parameter. If you have PHP<5, use one of the functions that can be found in the user's notes, in range(). Orio. Quote Link to comment https://forums.phpfreaks.com/topic/82819-expanding-numbers/#findComment-421192 Share on other sites More sharing options...
btherl Posted December 24, 2007 Share Posted December 24, 2007 What you've stated is a range of solutions .. it's much easier to work with something precise. For example: 1. Spread the gaps so that each is exactly 1.7 times the previous gap, allowing for fractional numbers 2. Round each fraction to the nearest number. Then you'll get something which is within your tolerance range (well I haven't checked this, I just picked 1.7 at random), but is exactly specified, and therefore easy to program. Does that kind of thing sound suitable? If so, we can look at deriving a formula that takes start, end, number of steps, and the multiplier (1.7 in the example) and produces the steps. Quote Link to comment https://forums.phpfreaks.com/topic/82819-expanding-numbers/#findComment-422177 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.