在PHP中复制Excel的循环参考公式 [英] Copying Excel's Circular Reference formula in PHP

查看:112
本文介绍了在PHP中复制Excel的循环参考公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在Excel中我有:



<$ A $ A = A25-A22(结果:8771.65)
A22 = A19 * 14.1%(结果:1236.80)
A25 = 10000

但是,当我尝试在PHP中计算时,它不会给我正确的结果:

  $ Tax = 0; 
$ Gross = 0;
$ Net_Amount = 10000;
$ Gross = $ Net_Amount - $ Tax;
$ Tax = $ Gross *(14.1 / 100);

有关如何在PHP中执行此操作的任何想法?

解决方案

默认情况下,当您有循环引用时,Excel将报告警告。例外是如果你已经告诉它来处理循环引用,直到预定义(你定义多少个)迭代次数。在PHP中执行后者的方法是使用一个循环来预定义的迭代次数。

  $ cycleCount = 12; 

$ Tax = 0;
$ Gross = 0;
$ Net_Amount = 10000;
($ cycle = 0; $ cycle< $ cycleCount; $ cycle ++){
$ Gross = $ Net_Amount - $ Tax;
$ Tax = $ Gross *(14.1 / 100);
}


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); 
}

这篇关于在PHP中复制Excel的循环参考公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆