note 20815 added to function.func-num-args
| From: | ashley at dcs dot warwick dot ac dot uk | Date: | Wed, 17 Apr 2002 08:40:26 +0000 |
| Subject: | note 20815 added to function.func-num-args | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-29463@lists.php.net to get a copy of this message | ||
If you want to pass the parameters on intact to another function, use func_get_args and
call_user_func_array (careful - this one is only available in recent PHP versions). For example:
/* Print an HTML tag. This accepts a variable number of arguments:
the first should be the name of the tag, followed by pairs of
arguments that describe keys and values. The values are printed
with surrounding double quote characters. */
function printTag() {
$numArgs = func_num_args();
if ($numArgs < 1) die("printTag given no arguments");
echo "<" . func_get_arg(0);
for ($i = 1; $i < $numArgs; $i+=2) {
echo " " . func_get_arg($i);
if ($i+1 < $numArgs)
echo "=\"" . func_get_arg($i+1) . "\"";
}
echo ">";
}
/* Print an HTML tag with a newline on the end */
function printTagNL() {
$args = func_get_args();
call_user_func_array("printTag", $args);
echo "\n";
}
printTagNL("input", "type", "hidden", "name",
"SORTORDER", "value", $columnNo);
--
http://www.php.net/manual/en/function.func-num-args.php
http://master.php.net/manage/user-notes.php?action=edit+20815
http://master.php.net/manage/user-notes.php?action=delete+20815
http://master.php.net/manage/user-notes.php?action=reject+20815