Test eshop - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Test eshop.php

  1.  <?php
  2.     $tndl = [500, 1234567890];
  3.     $tndc = [0.0857, 0.0932];
  4.     $tnnl = [100, 300, 1234567890];
  5.     $tnnc = [0.0432, 0.0489, 0.05321];
  6.  
  7.  
  8.  
  9.  
  10. $katDay = 890;
  11. $katNight = 195;
  12.  
  13. $i = 0; 
  14. $costEstNight = 0;
  15. while ($i < 6) {
  16.     echo '<br /> <br />$i counter is:'.$i.' <br /> ';
  17.     echo '$katNight: '.$katNight.' <br /> ';
  18.     echo 'tnnl: '.$tnnl[$i].' <br /> ';
  19.     echo 'tnnc: '.$tnnc[$i].' <br /> ';
  20.     
  21.     if ($i == 0 && $katNight >= $tnnl[$i]) {
  22.         $costEstNight = $costEstNight + ($tnnl[$i] * $tnnc[$i]);
  23.         echo '0:'.$costEstNight.' <br /> ';
  24.                 $diff = $tnnl[$i] - $tnnl[$i-1];
  25.         echo 'current: '.$tnnl[$i].' before: '.$tnnl[$i-1].' diff: '.$diff.' <br /> ';
  26.         $katNight = $katNight - $tnnl[$i];
  27.     // if it is not the last tier which has the Xlarge value of 1234567890.
  28.     } elseif ($i != 0 and ($tnnl[$i]) != 1234567890) {             
  29.         // The tier limit minus the tier limit of the previous tier.
  30.         // e.g. tier1_limit is 1000 and tier2_limit is 2000 -> consumption is 2000 kWh, 1000 from tier1 and 1000 from tier2.
  31.         $costEstNight = $costEstNight + (($tnnl[$i] - $tnnl[$i-1]) * $tnnc[$i]);     
  32.         $diff = $tnnl[$i] - $tnnl[$i-1];
  33.         echo 'current: '.$tnnl[$i].' before: '.$tnnl[$i-1].' diff: '.$diff.' <br /> ';
  34.  
  35.         echo '1:'.(($tnnl[$i] - $tnnl[$i-1]) * $tnnc[$i]).' <br /> ';
  36.         $katNight = $katNight - ($tnnl[$i] - $tnnl[$i-1]);
  37.     } else {
  38.         // Adds to the estimated cost the number of the remaining kWh multiplied by the cost of the kWh of this last tier.
  39.         $costEstNight = $costEstNight + ($katNight * $tnnc[$i]);
  40.                 $diff = $tnnl[$i] - $tnnl[$i-1];
  41.         echo 'current: '.$tnnl[$i].' before: '.$tnnl[$i-1].' diff: '.$diff.' <br /> ';
  42.         echo '2:'.$costEstNight.' <br /> ';
  43.         break;
  44.     }
  45.     $i = $i + 1;
  46. } 
  47. $attrPagio = 4.40;
  48. // Total cost estimates calculation
  49. $costEst = $attrPagio + (500*0.0857+390*0.0932) + $costEstNight;
  50. $costEstFormatted = number_format($costEst, 2, ',', '.');
  51. $costEstFormattedYearly = $costEst*12;
  52.  
  53. echo 'test <br />';
  54. echo $costEst;
  55.  
  56. //92.5635
File Description
  • Test eshop
  • PHP Code
  • 25 Sep-2020
  • 2.06 Kb
You can Share it: