I am trying to copy an Excel's Circular Reference formula in PHP.
In Excel I have:
A19 = A25-A22 (result: 8771.65)
A22 = A19*14.1% (result: 1236.80)
A25 = 10000
But, it does not give me correct result when i try to compute it in PHP:
$Tax = 0;
$Gross = 0;
$Net_Amount = 10000;
$Gross = $Net_Amount - $Tax;
$Tax = $Gross * (14.1/100);
Any idea on how to do this in PHP?
By default, Excel will report a warning when you have a circular reference. The exception is if you have told it to handle circular references up to a predefined (you define how many) number of iterations. The way to do the latter in PHP is to use a loop for a predefined number of iterations.
$cycleCount = 12;
$Tax = 0;
$Gross = 0;
$Net_Amount = 10000;
for ($cycle = 0; $cycle < $cycleCount; $cycle++) {
$Gross = $Net_Amount - $Tax;
$Tax = $Gross * (14.1/100);
}
来源:https://stackoverflow.com/questions/12213537/copying-excels-circular-reference-formula-in-php