Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to return an array from a function in PHP?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 36
    Comment on it

    If we have a function and we want to return multiple values from that function then we can easily return an array from function.Below is the example which returns a multiple array from function.

    function myFunc( ) {
    
    $myvar1 = 10;
    $myvar2 = 20;
    
    return array($myvar1, $myvar2);
    }
    

    Another option is to retrieving values returned from function.

    $results = myFunc();
    
    echo $results[0];
    
    echo $results[1];
    

 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: