今天就跟大家聊聊有關(guān)php中怎么處理可變長參數(shù)函數(shù),可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
1. func_num_args() -- 返回傳遞給函數(shù)的參數(shù)個數(shù)
int func_num_args ( void )
示例:
function open_database($DB, $cache_size_or_values=null, $cache_size=null) { switch (function_num_args()) { case 1: $r = select_db($DB); break; case 2: $r = select_db($DB, $cache_size_or_values); break; case 3: $r = select_db($DB, $cache_size_or_values, $cache_size); break; } return is_resource($r); }
2. func_get_arg() -- 返回指定的參數(shù)
mixed func_get_arg ( int arg_num)
參數(shù)列表中的第一個參數(shù)的 arg_num 是0
3. func_get_args() -- 以數(shù)組的形式返回參數(shù)列表
array func_get_args ( void )
示例:
看完上述內(nèi)容,你們對php中怎么處理可變長參數(shù)函數(shù)有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。