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

Some web applications, like Google Docs, store data generated by the users. Data that
I'm doing some searching of tags, and some users like cat while others like
Searching for some sample code for converting a point in WGS84 coordinate system to
Im searching a tool which allows me to specify some folders as bookmarks and
Quick question regarding CSS and the browser. I tried searching SO and found some
Some WPF controls (like the Button ) seem to happily consume all the available
Some API returns me XmlCursor pointing on root of XML Document. I need to
Some things look strange to me: What is the distinction between 0.0.0.0, 127.0.0.1, and
Some Eclipse plugins are mandated by your environment. The appropriate source code management plugin,
Some e-Marketing tools claim to choose which web page to display based on where

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.