【发布时间】:2016-01-23 17:08:29
【问题描述】:
我想在我的函数中使用数组作为参数,然后转换/提取该数组并将每个元素应用到第一个参数之后的另一个函数的参数中。
$args = [ $arg1, $arg2, ...];
function foo($one = 'string', $two='string', array $args = [])
{
// my stuffs
//here calling another function where need to pass arguments
// the first argument is required
// from second argument I want to apply array item individually.
// So this function has func_get_args()
call_another_function($one, $arg1, $arg2, ...);
}
那么我如何转换我的函数数组项并将每个项应用于call_another_function,从第二个参数到基于数组项的无穷大
【问题讨论】:
-
那么你的问题是什么?
-
@JohnConde 如何转换我的函数数组项并将每个项应用于
call_another_function,从第二个参数到基于数组项的无穷大 -
php 内置函数
call_user_func_array怎么样? php.net/manual/de/function.call-user-func-array.php -
call_another_funciton` 已经在使用它来获取所有函数参数。这里第一个参数已使用
array_slice在该函数中切片 -
@CodeLover
call_user_func_array以数组形式调用一个函数。我会根据你的代码给你一个例子。