Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to pass arguments to PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 359
    Comment on it

    Hello Reader's If you have some arguments that you want to pass into function and elements of that array you pass will then be received by your function as distinct parameters.

    For instance, if you have this function :

    function test() {
      var_dump(func_num_args());
      var_dump(func_get_args());
    }
    You can pack your parameters into an array, like this :
    
    $params = array(
      10,
      'glop',
      'test',
    );
    And, then, call the function :
    
    call_user_func_array('test', $params);
    

    OUTPUT:-

    int 3
    
    array
      0 => int 10
      1 => string 'glop' (length=4)
      2 => string 'test' (length=4)
    ie, 3 parameters ; exactly like iof the function was called this way :
    
    test(10, 'glop', 'test');
    

 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: