PHP 8.2.20 Released!

Voting

: four plus zero?
(Example: nine)

The Note You're Voting On

ashley at dcs dot warwick dot ac dot uk
22 years ago
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);
?>

<< Back to user notes page

To Top