note 42021 added to function.func-get-arg
| From: | anders at ingemann dot fakestuff dot de | Date: | Thu, 29 Apr 2004 20:18:20 +0000 |
| Subject: | note 42021 added to function.func-get-arg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69010@lists.php.net to get a copy of this message | ||
A pretty cool thing for user defined functions is only to submit the needed parameters. If you call
a function that has three optional parameters you have to define the two first ones (even if they
should stay like the defined standard in the function) before your are able to tell the function
what the third important parameter is. Instead you might as well just find out by the pattern or the
type of the submitted parameter which variable it should be assigned to.
like this:
<?
function whatever()
{
for($i=0;$i<func_num_args();$i++)
{
if(is_bool(func_get_arg($i))) $log_ip=func_get_arg($i);
if(is_int(func_get_arg($i))) $limit=func_get_arg($i);
if(is_string(func_get_arg($i))) $name=func_get_arg($i);
}
}
?>
Now you can call the function with any parameter you want.
e.g.:
<? whatever(3600); ?>
in that case $limit would be defined with 3600.
It doesn't matter if you do this:
<? whatever(3600,false); ?>
or this:
<? whatever(3600,"blaaah"); ?>
or this:
<? whatever("blaaah",true,3600); ?>
You may also use ereg(). Through that you're able to use more than one parameter as a string.
hmm probably ereg() is the best solution...
never mind.
just check it out ;-)
----
Manual Page -- http://www.php.net/manual/en/function.func-get-arg.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42021
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42021&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42021&report=yes
Search -- http://master.php.net/manage/user-notes.php