Php函数从一个变量开始

Php函数从一个变量开始,php,forms,function,Php,Forms,Function,我希望能够提交表单中的值,然后调用函数submitted,我的代码: <?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',

我希望能够提交表单中的值,然后调用函数submitted,我的代码:

<?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">

功能:

值1: 价值2: 价值3: 价值4: 价值5:
您可以使用
调用用户函数数组

call_user_func_array ( 'thefuncname' , your_parameters )
在您的情况下,它将类似于:

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

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

或者只是
echo$func(数组($a1、$a2、$a3、$a4、$a5))


(也许你不想要数组,所以你可以把
$func($a1,$a2,$a3等);

希望这是在某种登录之后,或者你将允许的函数调用列为白名单。非常感谢你的帮助@user2058217不客气,如果您还需要什么,请告诉我。@Evan从OP试图回应的内容来看,似乎这些确实是参数。不管怎样,你的答案是+1。
call_user_func_array($func, array($a1,$a2,$a3,$a4,$a5));
//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));
}