JasonGreen Posted September 13, 2009 Share Posted September 13, 2009 There doesn't seem to be a way around this. I want to be able to calculate values using variables but in such a way that the value continues to change - however, I cannot simply write out the number, I need a variable. Here is the problem, look at my example below, if I were to use calculations based on define variable, I would end up using longer and longer calculations and that would be a horible mess. Like this print $serveryear . " " . $servercost . " " . ($servercost * HIGH_DEPREC) . " " . ($servercost - $servercost * HIGH_DEPREC) . "\n"; print ($serveryear + 1) . " " . ($servercost - $dodgecost * HIGH_DEPREC) . " " . ($servercost - $servercost * HIGH_DEPREC * HIGH_DEPREC) . " " . ETC . "\n"; It just grows and grows!!!! At the same time I cannot define a variable for each and every calculation, that too is a mess that grows and grows. DELL SERVER– Depreciation over 5-year period (Factor: .20) YEAR Start Value Deprec Ending Value 2004 21297.00 4259.40 17037.60 2005 17037.60 3407.52 13630.08 2006 2007 2008 Any insights, comments, and suggestions will be greatly appreaciated. Thanks Quote Link to comment Share on other sites More sharing options...
Calver Posted September 14, 2009 Share Posted September 14, 2009 Jason, I think you need to use a function, something like this, then you can pass any values to it: <?php ShowDep("DELL SERVER", 21297, 2004, 5, 20); function ShowDep($title, $servercost, $serveryear, $numYears, $depRate){ $startValue = $servercost; $depValue = 0; $endValue = 0; print $title . "<br/>"; for ( $counter = 0; $counter < $numYears; $counter += 1) { $depValue = $startValue * $depRate / 100; $endValue = $startValue - $depValue; print $serveryear + $counter . " --- " . $startValue . " --- " . $depValue . " --- " . $endValue . "<br/>"; $startValue = $endValue; } } ?> I've only just started to learn PHP, so there's probably a better way to do it. Also, the output is untidy as I've not figured out the print statement yet! Quote Link to comment 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.