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 924553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:22:21+00:00 2026-05-15T19:22:21+00:00

I tried to access with $this->$arrDataName[$key] on the element with the key $key from

  • 0

I tried to access with $this->$arrDataName[$key] on the element with the key $key from the array $this->$arrDataName. But PHP interpretes that wrong.

I tried it with { } around the $arrDataName to $this->{$arrDataName}[$key], but it doesn’t work.

On php.net I found an advice, but I can’t realize it.

In order to use variable variables with arrays, you have to resolve an ambiguity problem. That is, if you write $$a[1] then the parser needs to know if you meant to use $a[1] as a variable, or if you wanted $$a as the variable and then the [1] index from that variable. The syntax for resolving this ambiguity is: ${$a[1]} for the first case and ${$a}[1] for the second.

Perhaps anyone can help me.

Thanks!

EDIT:

I think it doesn’t work, but I forgot to fill the array.
Finally it works. 🙂
This is the solution: $this->{$arrDataName}[$key]

  • 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-15T19:22:21+00:00Added an answer on May 15, 2026 at 7:22 pm

    Your syntax is correct:

    $this->{$varName}[$key]
    

    You can also use an extra variable for this:

    $myTempArr = $this->$arrDataName;
    
    $myTempArr[ $key ];
    

    IMHO, readability is better that way…

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

Sidebar

Related Questions

I've tried using the examples from MSDN for this but they seem to only
I tried to access 'this' after the implement of setinterval function, but couldn't access
I am trying to access a page method from centralized module. I tried putting
I get following error when trying to access Xampp from a network I've tried
How can I access the array to fetch the email address? I tried something
I uploaded my site on godaddy shared host. I can access this database from
Some tried to access this URL in my rails app http://domain.com/apply/share/script%3E%3Cscript%20type= Is this an
I'm aware that variants of this question have been asked before, but I do
I tried creating one, but the BackgroundWorker in Window1 couldn't access the ProgressBar in
I have a page that's derived from a master page. On this page, I

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.