RE: [PHP] String to Variable converstion
| From: | Cal Evans | Date: | Thu, 18 Jan 2001 01:17:45 +0000 |
| Subject: | RE: [PHP] String to Variable converstion | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-35229@lists.php.net to get a copy of this message | ||
try:
http://www.zend.com/manual/function.eval.php
Cal
http://www.calevans.com
-----Original Message-----
From: Paul Cohen [mailto:pcohen@networkoil.com]
Sent: Wednesday, January 17, 2001 6:14 PM
To: php-general@lists.php.net
Subject: [PHP] String to Variable converstion
Hello all,
I am trying to build an IRR calculator using PHP. The number of cash flow
streams I will have at any time will vary, so I am using a loop to build the
formula. Then I am iterating to solve the equation and output the solution.
As most of you know, I am solving the following for r:
0=SUM SERIES(CF(i)/{(1+r)^n))
I can build my formula sucessfully with the following;
$form="";
while ($row=mysql_fetch_array($result)){
$form.="$CF/pow((1+'$r'),$N)";
}
But it recognizes $form as a string, so when I put it in my "solution for r"
loop:
for($r=-1.00; $r<=1.00; $r=$r+.0001){
if($form>-.001 && $form < .001){
$IRR=round($r*100, 2);
}
}
echo "$IRR%<br>";
BTW, I have also tried building the $form as a variable, but since I don't
have a value for $r it just puts in zero and sets $form equal to the right
side of the equation. Therfore, instead of inserting a formula into my
"solution for r" loop, it inserts a constant for $form.
I think my solution is to build the formula as a string and then insert it
into my "solution for r" loop, convert it back to a real formula and then
iterate for the solution. Is this possible? If not, any suggestions?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net