0

I'm trying to make something like this to my variable data value...

$maxvalue = 0;
$basevalue = 0;
if($basevalue == 0) {$maxvalue = 0;}
else if ($basevalue == 1) {$maxvalue = 884;}
else if ($basevalue == 2) {$maxvalue = 1819;}
else if ($basevalue == 3) {$maxvalue = 2839;}

and so on.. i believe there is no exact computation on how the $maxvalue shifts as the basevalue increase. Can someone suggest me a simplier way to do this? thanks in advance!

6
  • Do you have more values? Maybe there is a pattern. Commented Jun 2, 2013 at 10:13
  • im not sure.. its really weird. here's 1-10 values.. 1-884, 2-1819, 3-2839, 4-3978, 5-5270, 6-6749, 7-8449, 8-10404, 9-12648, 10-15215 ... the fact that its until 100.. lol Commented Jun 2, 2013 at 10:18
  • so still no luck getting the pattern? =_= Commented Jun 2, 2013 at 10:38
  • As a matter of fact I do. Commented Jun 2, 2013 at 17:21
  • Did it work? Or did you put every value in an array after all? Commented Jun 5, 2013 at 15:21

3 Answers 3

6
$maxvalues = array(0, 884, 1819, 2839, ...);
$maxvalue  = $maxvalues[$basevalue];
Sign up to request clarification or add additional context in comments.

Comments

1

It looks like there's a pattern, almost like a faculty, but also with some other calculations. All numbers are multiples of 17. The following function returns the numbers you provided, so I think it might work for the higher numbers too:

function getMaxValue($base)
{
    // Factor of $base = 51 + $base^2 + Factor($base - 1). You
    // could solve that in a recursion, but a loop is generally better.
    $factor = 0;
    for ($i = 1; $i <= $base; $i++)
      $factor += 51 + ($i * $i);
    return $factor * 17;
}

// Test
for ($i = 0; $i < 100; $i++)
{
    echo "$i -- " . getMaxValue($i) . "<br>\n";
}

Comments

0

Here's the solution that prevented me putting all of them in an array..

$maxvalue = 17/6*(2*($basevalue*$basevalue*$basevalue)+3
($basevalue*$basevalue)+307*$basevalue);

Thanks for all the help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.