我正在尋找最優雅的方式來傳遞可變數量的參數來傳遞函數。php - 動態變量傳遞函數
考慮這樣的功能:
function abc ($x, $y, $l, $m) {
...
}
有一種優雅的方式沒有很多的「如果」或變量考取作爲一個變量數組來調用一個函數:
all ($x, $y, $l, $m) arguments
first three ($x, $y, $l) arguments
first and third ($x, $l) arguments
only second ($y) argument
last two ($l, $m) arguments
請諮詢。
您是否在尋找[func_get_args()](http://www.php.net/func_get_args)或替代它? – 2013-03-27 15:34:47
不幸的是 - 既不 – Kalreg 2013-03-27 15:40:09
因爲你不能在PHP中命名參數,函數如何理解你是否傳遞前3個或後3個參數?除非你使用數組(但你說你想避免它) – Uby 2013-03-27 15:49:13