| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| DesignersTalk > Functions with an unknown number of variables |
|
LinkBack | Thread Tools | Search this Thread |
|
|
#1 (permalink) |
|
shiro
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,630
|
Functions with an unknown number of variables
How do you write a function for which the number of variables to be inputted into it will change each time the function is used. Functions are generally written: function name ($variable1, $variable2, $variable3) { do something; } In the above function, the variables go up to $variable3, but I want to write a function in which they go up to $variableX where X is determined each time the function is run. Can anyone tell me how to do this? Specifically I am trying to do this in php, but I dont think that matters so much. Thanks guys! |
|
|
|
|
|
#4 (permalink) |
|
Senior Member
|
use func_num_args() and func_get_args(): PHP Code:
|
|
|
|
#5 (permalink) |
|
shiro
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,630
|
Cool, that one actually works even better for me. When using the other method mentioned earlier in the thread, had to manually set the variables for the array, which meant that I would have had to do that each time I called the function. This method looks like I can skip that step. |
|
![]() |