Variable-length Argument Lists in PHP with func_get_args()

Have you ever wanted to write a function in PHP that would accept a varying amount of arguments rather than requiring ones arbitrarily hard-coded? I can’t think of a reason why you would off the top of my head, but I know I’ve wished for such an ability before. There’s a PHP function called func_get_args() that will let you do that with minimal effort.

function myFunc() {

$args = func_get_args();

foreach ($args as $key => $value) {
echo "Argument {$key}: {$value} <br />";
}

}

You can call myFunc() with no arguments or like myFunc('hello world', 'lorem ipsum', 'dolor sit amet').