Jump to content

[SOLVED] Array Fails to hold variable


tsilenzio

Recommended Posts

I have a script that is suppose to mutiply a number by a percent if it falls within a range of numbers. However I see i didnt get the results I wanted.

 

Right now im not worried if it displays the expected output, I would however like to figure out why on my server when I uncomment line: 36 it shows that the arrays hold nothing :s

 

<?php

//$percent = array();
//$minrange = array();
//$maxrange = array();

$percent[0] = 0.9;
$percent[1] = 1.0;
$percent[2] = 1.1;
$percent[3] = 1.2;
$percent[4] = 1.3;

$minrange[0] = 1000000;
$minrange[1] = 10000000;
$minrange[2] = 50000000;
$minrange[3] = 100000000;
$minrange[4] = 250000000;

$maxrange[0] = 9999999;
$maxrange[1] = 49999999;
$maxrange[2] = 99999999;
$maxrange[3] = 249999999;
$maxrange[4] = 0;

$startInvest = 10000000;
$weeklyIncrease = 0;
$currInvest = $startInvest;
$days = 93;

// Loop thru all days
for($i = 0; $i < $days; $i++) {
  // Test each array element
  for($j = 0; $j < count($percent); $j++) {
    
    // For testing purposes -- NEXT LINE IS LINE 36
    //echo($j . ": " . $percent[j] . " " . $minrange[j] . " " . $maxrange[j] . "<br />");

    // See where the current investment fits into
    if(($currInvest > $minrange[j]) && ($currInvest < $maxrange[j])) {
      $currInvest *= (($percent[j] / 100) + 1);
      echo("Increased<br>");

      /*if(($days % 7) && ($weeklyIncrease > 500000)) { 
        $currInvest += $weeklyIncrease;
      }*/
    }
  }
}

echo("\$" . number_format($currInvest));
?>

 

Output:

$10,000,000

 

Expected Output:

25228286.93

 

Thanks in advance for your help!

Link to comment
https://forums.phpfreaks.com/topic/114833-solved-array-fails-to-hold-variable/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.