How to pass array as multiple parameters to function?

ぃ、小莉子 提交于 2019-12-01 15:16:38

You need to use call_user_func_array

call_user_func_array( array($method, $function), $params);

As of PHP 5.6 you can use argument unpacking:

function add($a, $b, $c) {
    return $a + $b + $c;
}

$numbers = [1, 2, 3];
echo add(...$numbers);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!