Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use key() finction in php ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 135
    Comment on it

    Hi Reader's,
    Welcome to FindNerd, today we are going to discuss about key() function in php.

    The key() function returns the index element of the current array position.
    Or we can say that returns the element key from the current internal pointer position.
    The key() function returns false on error.

    syntax of key() function

    key(array)
    

    array is required parameter

    you can take reference of bellow example:

    <?php
    //here define a variable of array
       $data = array(
        'Emp_name' => 'mac',
        'Emp_age' => 35,
        'Emp_dep' => 'account', 
    );
    //here call key()
    $key = key($data); 
    //print the $key
    var_dump($key);
    
    ?>
    

    output will come following of above example

    string(8) "Emp_name"
    

 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: