在PHP中做事的简单方法是什么? [英] What's an easy way of doing powers in PHP?
问题描述
我正试图制作一个脚本来帮助我的数学学习
I'm trying to make to make a script to help me with my maths
等式示例:y=(4*(x*2)^(2x+4))+4*x^2
要使它起作用,我只需要了解一下,只需将(x*2)
置于(2x+4)
的幂上,然后再将其归入原始等式即可,当然,您只需
For this to work, I just need it to understand that only (x*2)
needs to be put to the power of (2x+4)
, and then to sub that back into the original equation, which of course you can just eval()
an answer.
当我知道x值时,我想计算y的值.如果没有权力,这将相对容易.我只是不知道该怎么做.
I want to calculate the values of y, when I know an x value. This WOULD be relatively easy if it weren't for powers. I just can't get my head round how to do them.
我知道您可以使用pow()
,但是我正在尝试制作一个脚本来使用 any 等式.因此有点需要了解语法.
I know you can use pow()
, but I'm trying to make a script to work with any equation. So it sort of needs to understand the syntax.
任何建议如何解决?
推荐答案
对于用于评估公式的原生PHP沙箱(如Sjoerd的答案所述),请查看
For a native PHP sandbox for evaluating formulae, which works as Sjoerd's answer describes, take a look at the evalMath class on PHPClasses.
这篇关于在PHP中做事的简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!