Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数组作为函数参数提供,并在PHP中将其作为普通变量获取_Php - Fatal编程技术网

将数组作为函数参数提供,并在PHP中将其作为普通变量获取

将数组作为函数参数提供,并在PHP中将其作为普通变量获取,php,Php,首先,请参阅我的代码: //normal function function test($name, $password) { //do stuff... } //calling... test(['anonymous', '2020']); 所以,基本上我需要一个像上面这样的系统。我知道这个代码是错误的 我需要什么? 我将给出一个数组作为函数参数,在我的函数中,我需要得到这个数组作为一个普通变量 但是,有没有可能以另一种方式实现这些功能?Splat操作符…: //normal

首先,请参阅我的代码:

//normal function
function test($name, $password)
{
    //do stuff...
}

//calling...
test(['anonymous', '2020']);
所以,基本上我需要一个像上面这样的系统。我知道这个代码是错误的


我需要什么?
我将给出一个数组作为函数参数,在我的函数中,我需要得到这个数组作为一个普通变量



但是,有没有可能以另一种方式实现这些功能?

Splat操作符

//normal function
function test($name, $password)
{
    echo $name . ' ' . $password;
}

//calling...
test(...['anonymous', '2020']);
调用用户函数数组

//normal function
function test($name, $password)
{
    echo $name . ' ' . $password;
}

//calling...
call_user_func_array('test', ['anonymous', '2020']);

调用\用户\函数\数组()有问题,我应该猜你有什么问题?谢谢你的帮助。第一个是最好的例子。