Option A)
<?php
function registerTemplateA() {
// loop over every variable defined in the global scope,
// such as those you created there when calling this function
foreach($GLOBALS as $potentialKey => $potentialValue) {
$valueArgs = func_get_args();
if (in_array($potentialValue, $valueArgs)) {
// this variable seems to match a _value_ you passed in
$args[$potentialKey] = $potentialValue;
}
}
// you now have an associative array in $args
print_r($args);
}
registerTemplateA($name = "my template", $screenshot = "screenshot.png", $description = "nice template");
?>
Option B)
<?php
function registerTemplateB() {
// passing in keys as args this time so we don't need to access global scope
for ($i = 0; $i < func_num_args(); $i++) {
// run following code on even args
// (the even args are numbered as odd since it counts from zero)
// `% 2` is a modulus operation (calculating remainder when dividing by 2)
if ($i % 2 != 0) {
$key = func_get_arg($i - 1);
$value = func_get_arg($i);
// join odd and even args together as key/value pairs
$args[$key] = $value;
}
}
// you now have an associative array in $args
print_r($args);
}
registerTemplateB('name', 'my template', 'screenshot', 'screenshot.png', 'description', 'nice template');
?>
Option C)
<?php
function registerTemplateC($args) {
// you now have an associative array in $args
print_r($args);
}
registerTemplateC(array('name' => 'my template', 'screenshot' => 'screenshot.png', 'description' => 'nice template'));
?>
Conclusion: option C is the best "for minimum code"
(Note: this answer is valid PHP code, with open and close tags in the correct places, tested using PHP 5.2.x and should run on PHP 4 also... so give it a try if you must.)
register_templateargument?