Unlimited arguments for PHP function?(PHP函数的无限参数?)
问题描述
在 php 中如何创建一个可以接受无限数量参数的函数:myFunc($p1, $p2, $p3, $p4, $p5...);
In php how would you create a function that could take an unlimited number of parameters: myFunc($p1, $p2, $p3, $p4, $p5...);
我的下一个问题是:如何将它们传递给另一个函数,例如
My next question is: how would you pass them into another function something like
function myFunc($params){
anotherFunc($params);
}
但 anotherFunc 会像使用 anotherFunc($p1, $p2, $p3, $p4, $p5...) 调用它一样接收它们
推荐答案
call_user_func_array('anotherFunc', func_get_args());
func_get_args 返回一个数组,其中包含传递给调用它的函数的所有参数,并且 call_user_func_array 调用给定函数,并传递给它一个参数数组.
func_get_args returns an array containing all arguments passed to the function it was called from, and call_user_func_array calls a given function, passing it an array of arguments.
这篇关于PHP函数的无限参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP函数的无限参数?
基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
