来自变量的Php函数

I want to be able to submit a value from a form and then call the function submitted, my code:

<?php
include 'specs.php';
if (empty($_POST) === false) {
$func = $_POST['function'];
$a1 = $_POST['a1'];
$a2 = $_POST['a2'];
$a3 = $_POST['a3'];
$a4 = $_POST['a4'];
$a5 = $_POST['a5'];
echo $func.'('$a1', '$a2', '$a3', '$a4', '$a5');';
}
?>
<form action="" method="post">
Function:<br><input type="text" name="function"><hr>
Value 1: <input type="text" name="a1">
Value 2: <input type="text" name="a2">
Value 3: <input type="text" name="a3">
Value 4: <input type="text" name="a4">
Value 5: <input type="text" name="a5">
<input type="submit" value="Execute">

You can use call_user_func_array

call_user_func_array ( 'thefuncname' , your_parameters )

In your case it would be something like:

$func = $_POST['function'];
$parameters = array($a1, $a2, $a3, $a4, $a5);
call_user_func_array ( $func, $pameters);

replace

echo $func.'('$a1', '$a2', '$a3', '$a4', '$a5');';

with

call_user_func_array($func, array($a1,$a2,$a3,$a4,$a5));

Or just echo $func(array($a1, $a2, $a3, $a4, $a5));

(maybe you don't want an array, so you can just put $func($a1, $a2, $a3, etc);)

//suggust add some prefix on func ,then check function_exists
$func = 'auto_'.$_POST['function'];
if (function_exists( $func)) {
 $func(array($a1, $a2, $a3, $a4, $a5));
}