如何在每次使用不同变量的PHP中重新计算?

I have written a code to carry out a calculation using my formula, however I am having difficulty getting code to recalculate using my formula with different variables each time. Instead it is using the same variable. I would like each time it re-ran to use one of the randomly selected variable in the formula. Please see the code below. Note I am a beginner.

` PIIP Calculations

  $PIIPCount = 3 ;

  $Area = array(1000, 1500, 2000, 2500, 3000) ;
  $Height = array(100, 150, 200, 250, 250) ;
  $Poro = array(0.05, 0.10, 0.15, 0.20) ;
  $SatCon = array(0.02, 0.04, 0.06, 0.08) ;
  $OilVolFac = array(1.05, 1.1, 1.15, 1.2) ;

  //$AreaCount = count($Area);
  $AreaCount = $PIIPCount ;

  for ($i = 0; $i < $AreaCount ; $i++ ) {
    $RandA = $Area[array_rand($Area)];
    print "<li> $RandA <li>";
   }

   //$HeightCount = count($Height);
   $HeightCount = $PIIPCount ;

   for ($j = 0; $j < $HeightCount ; $j++ ) {
    $RandH = $Height[array_rand($Height)];
    print "<li> $RandH <li>";
   }

   // $PoroCount = count($Poro);
  $PoroCount = $PIIPCount ;

  for ($k = 0; $k < $PoroCount ; $k++ ) {
    $RandP = $Poro[array_rand($Poro)];
    print "<li> $RandP <li>";
   }

   // $SatConCount = count($SatCon);
   $SatConCount = $PIIPCount ;

    for ($l = 0; $l < $SatConCount ; $l++ ) {
     $RandS = $SatCon[array_rand($SatCon)];
     print "<li> $RandS <li>";
    }

     // $OilVolFacCount = count($OilVolFac);
     $OilVolFacCount = $PIIPCount ;

      for ($m = 0; $m < $PoroCount ; $m++ ) {
      $RandO = $OilVolFac[array_rand($OilVolFac)];
       print "<li> $RandO <li>";
       }

        $arrayA = array($RandA) ;
        print '<br $arrayA[0] />' ;
        $arrayA1 = $arrayA[0] ;
        print $arrayA1 ;

        $arrayH = array($RandH) ;
        print '<br $arrayH[0] />' ;
        $arrayH1 = $arrayH[0] ;
        print $arrayH1 ;

        $arrayP = array($RandP) ;
        print '<br $arrayP[0] />' ;
        $arrayP1 = $arrayP[0] ;
        print $arrayP1 ;

        $arrayS = array($RandS) ;
        print '<br $arrayS[0] />' ;
        $arrayS1 = $arrayS[0] ;
        print $arrayS1 ;

       $arrayO = array($RandO) ;
       print '<br $arrayO[0]  />' ;
       $arrayO1 = $arrayO[0];  
       print '<br $arrayO1 />';

       $Sample = array(array($RandA), array($RandH), array($RandP), array($RandS),       `enter code her`array($RandO));
      print'<br $Sample[3][1] >' ;


      for ( $n = 0 ; $n < $PIIPCount; $n++) {
      $PIIPCalc = (($arrayA1*$arrayH1*$arrayP1)*(1-$arrayS1)/$arrayO1) ;
       print  round($PIIPCalc).  " " ;
       }

       ?>
       </body>
       </html>

Variables are placeholders in an algorithm. You don't "run an algorithm with different variables", that would mean that you change the algorithm; no, you run an algorithm with different values for its variables.

It's rather unclear what variables you're trying to change here, but consider this:

function myAlgorithm($value) {
    // do something
    return $result;
}

echo myAlgorithm('foo');
echo myAlgorithm('bar');
echo myAlgorithm('baz');

The algorithm and the variables in myAlgorithm do not change, but you're running the same algorithm with different input values. I believe this is what you want; learn about functions.

You can do essentially the same with loops:

foreach (array('foo', 'bar', 'baz') as $value) {
    // do something
    echo $result;
}

You are not changing the values in the variables of your bottom for loop where you are doing the calculation. Also as you are looping over the arrays at the top getting random values, you are just overwriting the value of your $Rand{whatever} variable. This whole thing could be done with a single loop like:

<?php
$PIIPCount = 3 ;

$Area = array(1000, 1500, 2000, 2500, 3000) ;
$Height = array(100, 150, 200, 250, 250) ;
$Poro = array(0.05, 0.10, 0.15, 0.20) ;
$SatCon = array(0.02, 0.04, 0.06, 0.08) ;
$OilVolFac = array(1.05, 1.1, 1.15, 1.2) ;

//loop for count of PIIPCount
for($i=0; $i<$PIIPCount; $i++){
    //get one value from each array at random and save it on our blank arrays
    $randA = $Area[array_rand($Area)];
    $randH = $Height[array_rand($Height)];
    $randP = $Poro[array_rand($Poro)];
    $randS = $SatCon[array_rand($SatCon)];
    $randO = $OilVolFac[array_rand($OilVolFac)];

    $PIIPCalc = (($randA*$randH*$randP)*(1-$randS)/$randO) ;
    print "(($randA*$randH*$randP)*(1-$randS)/$randO) = ";
    print  round($PIIPCalc).  "<br>" ;
}

http://codepad.viper-7.com/FddttW

On each iteration of the for loop I'm getting new random values into my $rand variables and those are being used in the formula.