Specific method variable argument lists PHP function introduction

PHP function of the variable parameter list can be achieved by three functions _get_args (), func_num_args (), func_get_arg (). Below this we made a detailed introduction.

AD: 2014WOT Global Software Developer Forum Beijing station program video released

 

Perhaps for PHP junior programmer for PHP functions are not fully skilled master. Implementation of variable argument lists PHP functions we introduce today is mainly the use of func_get_args (), func_num_args (), func_get_arg () function to achieve the three systems, in which func_get_args () function to get the list of arguments as an array specific usage see the manual.

 

PHP function of the variable parameter list code is as follows:

 

  1. < ?php  
  2. /**  
  3. * Multi function parameter list  
  4. *  
  5. */  
  6. function multiArgs()  
  7. {  
  8. / ** Returns the list of arguments as an array * /  
  9. $args = func_get_args();  
  10. Number / parameter ** * /  
  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. ?> 

These are related to implementation of variable argument lists PHP functions.

Reproduced in: https: //www.cnblogs.com/zhangchenliang/p/3938342.html

Guess you like

Origin blog.csdn.net/weixin_34104341/article/details/93495435