Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Extract method in PHP

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 173
    Comment on it

    Sometime we may need to use the same variable name that you are using in the query or simply in an associative array.

    Lets say you have an associative array :

    $arr = array( 'totalLimit' => 50, 'limit' => 10 );
    

    The usually what we do is to find the array element by their indexes. i.e.,

    $totalLimit = $arr['totalLimit'];
    echo $totalLimit;
    

    You have a better way of doing the same thing in php i.e.

    $arr = array( 'totalLimit' => 50, 'limit' => 10 );
    extract($arr);
    

    now you can directly use the keys as the variable name:

    echo $totalLimit;
    echo $limit;
    
    O/P: 50 10
    

    Definition and Usage

    The extract() function imports variables into the local symbol table from an array. This function uses array keys as variable names and values as variable values. For each element it will create a variable in the current symbol table.This function returns the number of variables extracted on success. - By W3SCHOOLS

 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: