Monday, March 14, 2011

func_num_args and func_get_args - php

func_num_args — Returns the number of arguments passed to the function
func_get_args -- Returns an array comprising a function's argument list.


 function countAll() {
       $numargs = func_num_args();
       echo "Number of arguments: $numargs\n";
   }
     countAll(ab, bc, cd, df);  // Prints 'Number of arguments: 3'
    
   function getName() {
      if(func_num_args()>0){
        echo func_get_arg(0);      
      }else{
        echo "nothing";
      }
     
   }
     getName(ab, bc, cd, df);  // Prints 'ab'

No comments:

Post a Comment