note 20815 modified in function.func-num-args by danbrown
| From: | danbrown@php.net | Date: | Sat, 19 Jul 2008 21:53:38 +0000 |
| Subject: | note 20815 modified in function.func-num-args by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141772@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:
<?php
/* 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);
?>
--was--
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://php.net/manual/en/function.func-num-args.php