Retrieve an array value at a function call
When we have a function that returns a array, we can retrieve any specific value from that array just putting the key after the function call. Let's see:
function my_fn() {
return array( 'key1'=>'value1',
'key2'=>'value2' );
}
echo my_fn()['key1'];
I have using this for a while and I like the way we can just pick up a value from the array without create a variable to handle the return value.
But what do you think? I wanna know if it is a good practice so please let your comments!
Written by Everton Silva
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#