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)