PHP function structure issue
I have a function
function me($a, $b, $c, $d) {
}
I want to add all this in array by array_push
is there a variable enable me do this in one step.
I want echo all this on ($a,$b,$c,$d)
by foreach
I don't know it i will assume any variable in () will equal $anything
function me($a,$b,$c,$d){
foreach ($anything as $key => $value){
echo $value; // i want return 开发者_如何学JAVA$a,$b,$c,$d values
}
}
Any one understand what I want? I want foreach the function and I cant explain because I don't understand
function(void){
foreach(void) { }
}
I want foreach all variables between () OK in function**(void)**{
I guess that you are talking about variable number of arguments. This example below is from the php site and uses func_num_args
to get the actual number of arguments, and func_get_args
which returns an array with the actual arguments:
function me()
{
$numargs = func_num_args();
echo "Number of arguments: $numargs<br />\n";
if ($numargs >= 2) {
echo "Second argument is: " . func_get_arg(1) . "<br />\n";
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "<br />\n";
}
}
me (1, 2, 3);
You could try func_get_args(). Calling that will give you an array (numerically indexed) containing all of the parameter values.
I don't really understand what you are asking, though.
func_get_args()
returns all arguments passed to the function.
You can use func_get_args()
like Jasonbar says:
function a() {
foreach (func_get_args() as $param) {
echo $param;
}
}
a(1,2,3,4); // prints 1234
a(1,2,3,4,5,6,7); // prints 1234567
精彩评论