<?php
$e = "n * 2";
function incr($expression) {
$expression = str_replace('n', '$n', $expression);
$func_body = "
\$increment = (int)($expression + 1);
return \$increment;";
return create_function('$n', $func_body);
}
$increment_func = incr($e);
echo call_user_func($increment_func, 2);
?>
Output:
5
No comments:
Post a Comment