无限数量的参数PHP函数 [英] PHP function with unlimited number of parameters
问题描述
我怎样写,可以接受的参数数量不受限制的函数?
什么我试图做的是一个封装下面的类中创建一个函数:
$ stmt-> bind_param('SSSD,$code,$语言,$官员,$%)的;
以上建议都是不错的,但我不认为他们会适合你的情况。
$ stmt-> bind_param('SSSD,$code,$语言,$官员,$%)的;
如果你想换行此功能,您将需要通过的引用的原来的参数变量的函数bind_param。我不认为func_get_args()给你这个,它给你数值代替。因此,将无法使用这些传递给父函数。我与作战想扩展mysqli_stmt永不来到满意的解决方案时,类似的问题。
这是不是一个真正的回答你的问题我很害怕,只是一个警告,其他参数不得以参数的任意数目的特定应用程序。
How do I write a function that can accept unlimited number of parameters?
What am trying to do is create a function within a class that wraps the following:
$stmt->bind_param('sssd', $code, $language, $official, $percent);
The above suggests are all good, but I don't think they will be suitable for your situation.
$stmt->bind_param('sssd', $code, $language, $official, $percent);
If you want to wrap this function, you will need to pass references to the original argument variables to the bind_param function. I don't think func_get_args() gives you this, it gives you values instead. Thus it won't be possible to use these to pass to the parent function. I battled with a similar issue when trying to extend mysqli_stmt and never came to satisfactory solution.
This is not really an answer to your question I'm afraid, just a warning that other arguments may not work in your particular application of arbitrary number of arguments.
这篇关于无限数量的参数PHP函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!