Çok boyu beyan argümanları doldurmak için yeterli olduğu gibi, herhangi bir işleve bağımsız değişken bir dizi kabul edebilir.
<?php
function test ($a, $b) { }
test(3); // error
test(4, 5); // ok
test(6,7,8,9) // ok
?>
sen işlevleri
func_get_args()
,
func_num_args()
ve
func_get_arg($i)
kullanın
test()
geçirilen ekstra un-adlandırılmış argümanlar erişmek için:
benim PHP parametrelerle bir JavaScript-vari bir yaklaşım ister
<?php
// Requires at least one param, $arg1
function test($arg1) {
// func_get_args() returns all arguments passed, in order.
$args = func_get_args();
// func_num_args() returns the number of arguments
assert(count($args) == func_num_args());
// func_get_arg($n) returns the n'th argument, and the arguments returned by
// these functions always include those named explicitly, $arg1 in this case
assert(func_get_arg(0) == $arg1);
echo func_num_args(), "\n";
echo implode(" & ", $args), "\n";
}
test(1,2,3); // echo "1 & 2 & 3"
?>
oldukça emin 'func_get_args () Bu aslında bu ilk çözüm yerine kullanmak istediğiniz şeydir. – Toskan