相比于eval,create

执行php表达式字符串,相比于eval,create_function也许是个更好的选择PHP eval() 函数定义和用法

eval() 函数把字符串按照 PHP 代码来计算。

该字符串必须是合法的 PHP 代码,且必须以分号结尾。

如果没有在代码字符串中调用 return 语句,则返回 NULL。如果代码中存在解析错误,则 eval() 函数返回 false。

语法
eval(phpcode)
例子
<?php
\(string = "beautiful";
\)time = “winter”;
\(str = 'This is a \)string \(time morning!';
echo \)str. “
”; eval(“$str = &#34;\(str\&#34;;&#34;);</code> echo \)str; ?&gt;

输出:

This is a \(string \)time morning!
This is a beautiful winter morning! 


    

输出:

This is a \(string \)time morning!

This is a beautiful winter morning!


//用create_functoin()创建匿名函数

//因为该函数已被弃用,部分编辑器会给出警告,多说无益

//知道这个函数曾经来过这个世界上就足够了

\(func1= create_function(&#39;\)a,\(b&#39;, &#39;return (\)a+\(b);&#39;);echo\)func1(10,20);