[PHP-users 24777] Re: 文字列の計算式を計算して変数に格納したい

Takuo Kobayashi asuka @ h5.dion.ne.jp
2005年 3月 3日 (木) 14:25:17 JST


On Thu, 03 Mar 2005 13:49:52 +0900
Hiroshi Ishiura <issy777 @ e-entrance.org> wrote:
> $a = "5000";
> $str = "($a*0.2)+2000";
> $total = eval("print($str);");
> 
> evalでの出力ではできるんですが変数への代入するやり方がわかりません。
> つまり(5000*0.2)+2000=3000の3000を$totalにいれたいのです。


$a = 5000;
$str = 'return ($a*0.2)+2000;';

$total = eval($str);
echo $total;


とか、、、。$total に入れているっていのを後(eval時)に決定できてよさげ
な感じが。


- ahiru



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.6.0 - Release Date: 2005/03/02



PHP-users メーリングリストの案内