0

Most of the time, when there is a function named func1 and it returns an array, I use this method to access a specific index of that returned array:

$myarray=func1();
echo $myarray['AssIndex'];

Is there a way to access it in a single line? Something like this?

// the brackets are not working. this is only to make my meaning clear.
echo {func1}['AssIndex'];

1 Answer 1

3

As of PHP 5.4, you can do this:

echo func1()['AssIndex'];

This is called Function Array Dereferencing.

Sign up to request clarification or add additional context in comments.

1 Comment

You are awesome and legen...wait for it... dary legendary!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.