Home >Backend Development >PHP Tutorial >PHP中有没有计算“四则混同运算”表达式的简单方法

PHP中有没有计算“四则混同运算”表达式的简单方法

WBOY
WBOYOriginal
2016-06-13 12:08:49943browse

PHP中有没有计算“四则混合运算”表达式的简单方法?
例如,有一个字符串"11+22+33",怎么得出结果是66?

别说用逆波兰式、压栈出栈啥的,都快忘光了。。。
------解决思路----------------------
echo eval("return $str;");
------解决思路----------------------
$str = "11+22+33";
echo eval("return $str;");

Statement:
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