php函数,用于在单个数组中获取n个参数

php函数,用于在单个数组中获取n个参数,php,arrays,parameters,Php,Arrays,Parameters,我对php不熟悉,我想创建一个函数,将n个参数作为单个数组接受。比如说 function select(user,pass,salt,... n) 在上面的函数中,传递的参数应该在单个数组中获得,如下所示 { $select; \\this variable gets all those passed parameters as a single array } 您可以将整个数组作为函数参数,请参见下面的示例 // define parameters for function $para

我对php不熟悉,我想创建一个函数,将n个参数作为单个数组接受。比如说

function select(user,pass,salt,... n)
在上面的函数中,传递的参数应该在单个数组中获得,如下所示

{
$select; \\this variable gets all those passed parameters as a single array 
}

您可以将整个数组作为函数参数,请参见下面的示例

// define parameters for function 
$params = array(
    'user' => 'admin', 
    'pass' => 'abcd', 
    'n' => 'nth_param'
); // salt 'param' isn't defined

// define function 'select'   
function select ($params) {
    $user = isset($params['user']) ? $params['user'] : NULL;
    $salt = isset($params['salt']) ? $params['salt'] : NULL; // you can set default value instead of NULL here
    // ...

    return '...';
}

// function call
select ($params);

使用func_get_args函数获取传递给函数的所有参数并存储在数组中

<?php

function select("user","pass","salt",... n)
{

$arg_list = func_get_args();
print $arg_list[0];

}

//this will output "user"

?>

,然后说出你想要的。或者使用。我不是传递数组,我是传递n个值给函数传递的值应该被捕捉到数组@the_big_blackbox我不是传递数组我不想传递数组作为参数,我是传递n个值给函数传递的值应该被捕捉到数组@panther