Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1051999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:01:21+00:00 2026-05-16T17:01:21+00:00

Some searching through Google (and my own experience) shows that in PHP you can’t

  • 0

Some searching through Google (and my own experience) shows that in PHP you can’t grab an array element when it’s been returned from a function call on the same line. For example, you can’t do:

echo getArray()[0];

However, I’ve come across a neat little trick:

echo ${!${false}=getArray()}[0];

It actually works. Problem is, I don’t know why it works. If someone could explain, that would be great.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:01:22+00:00Added an answer on May 16, 2026 at 5:01 pm
    echo ${!${false}=getArray()}[0];
    

    This is how it works, step by step

    ${false}=getArray()
    

    assigns the result of getArray to a variable with an empty name (” or null would work instead of false)

    !${false}=getArray()
    

    negates the above value, turning it to boolean false

     ${!${false}=getArray()}
    

    converts the previous (false) value to an (empty) string and uses this string as a variable name. That is, this is the variable from the step 1, equal to the result of getArray.

    ${!${false}=getArray()}[0];
    

    takes index of that “empty” variable and returns an array element.

    Some more variations of the same idea

    echo ${1|${1}=getArray()}[1];
    echo ${''.$Array=getArray()}[1];
    
    function p(&$a, $b) { $a = $b; return '_'; }
    echo ${p($_, getArray())}[1];
    

    As to why getArray()[0] doesn’t work, this is because php team has no clue how to get it to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been searching all over SO and reading through google docs but I can't
I have been searching through here and google for a few days now, trying
I've been searching through the Devise RDocs, Google, on this site for answers to
After searching through some existing libraries for JSON, I have finally ended up with
I've done some searching, but can't seem to find a way to do this.
I've done some searching, but I've been unable to fully understand how this is
My apologies if this has been answered before or is obvious...did some searching here
I've been searching and found jFreeChart , Python Google Chart and matplotlib . Searching
I'm trying to develop an application that will simulate a route through Google's Navigation
After searching the developer docs, google and other sites I still can't find how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.