PHP函數可變參數列表的具體實現方法介紹

來源:互聯網
上載者:User

標籤:style   http   color   io   strong   for   ar   2014   art   

PHP函數可變參數列表可以通過_get_args()、func_num_args()、func_get_arg()這三個函數來實現。我們下面就對此做了詳細的介紹。

AD:2014WOT全球軟體技術峰會北京站 課程視頻發布

 

也許對於PHP初級程式員來說,對於PHP函數並不能完全熟練的掌握。我們今天為大家介紹的PHP函數可變參數列表的實現方法主要是利用func_get_args()、func_num_args()、func_get_arg()這三個系統函數來實現的,其中func_get_args()函數以數組的形式獲得參數列表,具體用法參看手冊。

  • 教你快速實現PHP全站許可權驗證
  • PHP記憶體回收機制防止記憶體溢出
  • 技巧分享 PHP效能最佳化
  • PHP函數isset()只能用於變數
  • 迅速學會PHP加密解密技巧

 

PHP函數可變參數列表代碼如下:

 

  1. < ?php  
  2. /**  
  3. * 函數的多參數列表的實現  
  4. *  
  5. */  
  6. function multiArgs()  
  7. {  
  8. /** 以數組的形式返回參數列表 */  
  9. $args = func_get_args();  
  10. /** 參數的個數 */  
  11. $args_num = func_num_args();  
  12. foreach ( $args as $key => $value )  
  13. {  
  14. echo ‘This is ‘,$key+1,‘th argument:‘,$value,‘<br/>‘;  
  15. }  
  16. echo ‘Number of args is ‘,$args_num;  
  17. }  
  18. multiArgs(‘one‘,‘two‘,‘three‘);  
  19. /** output */  
  20. /**  
  21. This is 1th argument:one  
  22. This is 2th argument:two  
  23. This is 3th argument:three  
  24. Number of args is 3  
  25. */  
  26. ?> 

以上就是PHP函數可變參數列表的相關實現方法。

PHP函數可變參數列表的具體實現方法介紹

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.