newttster Posted January 24, 2011 Posted January 24, 2011 I'm trying to find a shorter way of getting this idea to work ... I've considered arrays, elseif statements even a while loop but they would lead to well over 2000 lines of code. This is what I am trying to implement; If 'x'=1 then 'y'='z'*1 elseif 'x'=2 then 'y'='z'*1.2 elseif 'x'=3 then 'y'='z'*1.4 elseif 'x'=4 then 'y'='z'*1.6 elseif 'x'=5 then 'y'='z'*1.8 elseif 'x'=6 then 'y'='z'*2 elseif 'x'=7 then 'y'='z'*2.2 etc. I want the process to check 'x' where 'x' can be a number between 1 and 2000 and that the multiplier of 'z' increases by .2 for each 'x' increase, so that if 'x'=98 then the process will pull 'z' as 'z'='z'*11.4 and so on. Any ideas or suggestions that can point me in the right direction would be greatly appreciated. Thanks. Quote
Danny696 Posted January 24, 2011 Posted January 24, 2011 Something like this i think; $z = 5; //for example $y = 1; for($i = 1, $add = 0.2; $i <= 2000; $i++) { $y = ($i == 1) ? $y : $y+$add; if($i == $x) { $y = $z * $y; } } Quote
Blade Maker Posted January 25, 2011 Posted January 25, 2011 Wouldn't a Case work aswell? Or am I wrong. Edit: nvm, did not read it properly. Quote
newttster Posted January 25, 2011 Author Posted January 25, 2011 @Danny696 ... I tried your idea and unfortunately I couldn't get it to work the way I need it too. Thank you for your suggestion just the same. @Dayo ... if you were close by ... I'd kiss you. :P Your suggestion works perfectly. Thank you very much. Quote
Dayo Posted January 25, 2011 Posted January 25, 2011 No problem mate ... Algebra was my strongest subject in maths :) did you need the PHP code? Quote
newttster Posted January 25, 2011 Author Posted January 25, 2011 Thanks Dayo ... I think I have it so far. I'm just setting up my "mock" tables and such first then I will give it a more in depth test to make sure it all works the way I need it to. Would you like to see it when I have it all set up? Quote
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.