Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • func_get_args and func_num_args functions PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 110
    Comment on it

    Welcome to Findnerd. In a series of PHP functions, today i am going to discuss the PHP function func_get_args. PHP is a scripting language which uses programing concept in much easy way. func_get_args came in PHP4 and it is being modified in later versions as well so main concept behind to use this function is that using this function we can use dynamic parameters in a function. Don't need to write the parameters in the function. Use this function and change the number of argument if required. First of all I want to mention, it does not take any argument and returns array of current function. We can take an small example to understand the working.

     

    function findNerd()
    	{
    		$args_count = func_num_args();
    		print_r($args_count);
    		echo "<br/>";
    		$args_list = func_get_args();
    			print_r($args_list);
    	}
    findNerd(1, 2, 'fsgdsg');

     

    In above example we are using two functions one to get the count of the parameters that is func_num_args and other to get the parameters in an array. You can use this arguments as per the requirement.

    If you include a file inside function then use that function inside that file then it will return false and warning  called from global scope with PHP 5.3 and later versions. Please have a look.

    function findNerd()
    	{
    		include("findNerd_script.php");
    	}
    findNerd(1, 2, 'fsgdsg');
    
    //file findNerd_script.php 
    
    
    $args_list = func_get_args();
    print_r($args_list);

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: