Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Array deferencing in php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 121
    Comment on it

    Array Dereferencing is a good feature which is available in PHP 5.4 version. using this user can directly access an array object directly of a method a functions. The purpose of using this is to reduce the unnecessary lines of code because of the extra code for added variables so using this it reduce the space complexity and make the code simple to use.This function prevents user from having to create temporary variables which will reduce several lines of code.

     function myfunc()
        {
            return array('key1' => 'value1', 'key2' => 'value2');
        }
    
        echo myfunc()['key1'];
    

    So it translates to use the following given piece of code in php.

    function myfunc()
    {
      return array('key1' => 'value1', 'key2' => 'value2');
    }
    
    $obj = myfunc();
    echo $obj['key1'];
    

 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: