Home > Backend Development > PHP Tutorial > ,字符串,运算符,整型相加减。怎么写式子?

,字符串,运算符,整型相加减。怎么写式子?

WBOY
Release: 2016-06-23 13:15:38
Original
1161 people have browsed it



输出的$sum是一个式子
我希望它直接输出一个结果。
应该怎么办?


回复讨论(解决方案)

$a = '3';$b = '4';$c = '+';$sum = $a.$c.$b;echo $sum, PHP_EOL;//可以这样echo eval("return $sum;"), PHP_EOL;//也可以这样$f = create_function('', "return $sum;");echo $f();
Copy after login
Copy after login
3+4
7
7

$a = '3';$b = '4';$c = '+';$sum = $a.$c.$b;echo $sum, PHP_EOL;//可以这样echo eval("return $sum;"), PHP_EOL;//也可以这样$f = create_function('', "return $sum;");echo $f();
Copy after login
Copy after login
3+4
7
7



感谢帮助
echo eval("return $sum;");
这段代码是有用的。
后面的那一段定义的变量f测试的时候发现出错。

拜托你抄仔细了

$f = create_function('', "return $sum;");echo $f();
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template