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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:35:46+00:00 2026-05-13T11:35:46+00:00

Is it possible to create a variable variable pointing to an array or to

  • 0

Is it possible to create a variable variable pointing to an array or to nested objects? The php docs specifically say you cannot point to SuperGlobals but its unclear (to me at least) if this applies to arrays in general.

Here is my try at the array var var.

     // Array Example
     $arrayTest = array('value0', 'value1');
     ${arrayVarTest} = 'arrayTest[1]';
     // This returns the correct 'value1'
     echo $arrayTest[1];
     // This returns null
     echo ${$arrayVarTest};   

Here is some simple code to show what I mean by object var var.

     ${OBJVarVar} = 'classObj->obj'; 
     // This should return the values of $classObj->obj but it will return null  
     var_dump(${$OBJVarVar});    

Am I missing something obvious here?

  • 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-13T11:35:46+00:00Added an answer on May 13, 2026 at 11:35 am

    Array element approach:

    • Extract array name from the string and store it in $arrayName.
    • Extract array index from the string and store it in $arrayIndex.
    • Parse them correctly instead of as a whole.

    The code:

    $arrayTest  = array('value0', 'value1');
    $variableArrayElement = 'arrayTest[1]';
    $arrayName  = substr($variableArrayElement,0,strpos($variableArrayElement,'['));
    $arrayIndex = preg_replace('/[^\d\s]/', '',$variableArrayElement);
    
    // This returns the correct 'value1'
    echo ${$arrayName}[$arrayIndex];
    

    Object properties approach:

    • Explode the string containing the class and property you want to access by its delimiter (->).
    • Assign those two variables to $class and $property.
    • Parse them separately instead of as a whole on var_dump()

    The code:

    $variableObjectProperty = "classObj->obj";
    list($class,$property)  = explode("->",$variableObjectProperty);
    
    // This now return the values of $classObj->obj
    var_dump(${$class}->{$property});    
    

    It works!

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

Sidebar

Related Questions

Possible Duplicate: Create an Array of the Last 30 Days Using PHP I am
Is it possible to create a PHP function that takes a variable number of
Is it possible to create a new array in windows workflow? More specifically, in
Is it possible to create a dynamic variable in PHP based on the value
Is it possible to create a variable name based on the value of a
Is this possible to create new {variable = x.something} and specify variable name dynamically?
Is it possible to create a template function that takes a variable number of
Is it possible to create an Iframe using document.createElement(iframe); and then set a variable
I'm relatively new to PHP. I'm wondering if it's possible to simply create a
Is it possible to create a django template that can be used (nested) inside

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.