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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:24:11+00:00 2026-05-22T16:24:11+00:00

I have an array of arrays in PHP and I want to access the

  • 0

I have an array of arrays in PHP and I want to access the variable-name of each array (as a string) inside the container array.

Have:

$container = array($array1, $array2, $array2);

Need:

foreach ($container as $anArray) {
    {...some other code...}
    echo variable_name($anArray);  // output: array1 array2 array3
}

I’m trying to run a foreach loop to output the name of each array with functions like the following (suggested in the PHP manual):

function vname(&$var, $scope=false, $prefix='unique', $suffix='value') {
    if($scope) $vals = $scope;
    else      $vals = $GLOBALS;
    $old = $var;
    $var = $new = $prefix.rand().$suffix;
    $vname = FALSE;
    foreach($vals as $key => $val) {
        if($val === $new) $vname = $key;
    }
    $var = $old;
    return $vname;
}

But that function understandably only outputs: anArray (x3)

I need to output: array1 array2 array3

Any suggestions?

  • 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-22T16:24:11+00:00Added an answer on May 22, 2026 at 4:24 pm

    It is not possible to retrieve the “names” array1, array2, array3 from an array created with array($array1, $array2, $array3). Those variable names are gone.

    You can make the array keys the names though:
    array('array1' => $array1, 'array2' => $array2, 'array3' => $array3)
    A shortcut for this is compact('array1', 'array2', 'array3').

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

Sidebar

Related Questions

I want to access the data in the php array. I have tried array[0]
hi i have multidimensional array in php i want to remove an index from
I have a PHP array, say, $array = Array(Name1,Name2,Name3,Name4,Name5); I want to find the
I have an multi-dimensional array that I want to send to a PHP script
I have an html document with multiple commented-out PHP arrays, e.g.: <!-- Array (
I have an array generated by PHP array( array( 'name'=>'node1', 'id' => '4' ),
In my PHP-side I have an array of associative arrays like so: Array (
I want to access the $name variable, which is defined in a while loop,
How can I access a JSON array from a PHP variable in an external
I have taken a print_r of the variable and want access some information from

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.