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

WBOY
Release: 2016-06-13 12:08:49
Original
911 people have browsed it

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

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

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!