Jump to content

function to get array name


nikosliapis

Recommended Posts

Hello everyone

Let's say that i have a function that does something to a given array:

 

function any_name($array) {

    do something....

}

 

What i want is a way to "get" the name of the array and echo it out.

For example if i use the function as:

echo $var = any_name($example1);    The output to be: $example1

or

echo $var = any_name($example2);    The output to be: $example2

 

Thank you very much for your time.
Link to comment
Share on other sites

"trq" thank you for your interest.

The "Whole story" is that i'm working on a function that will display a 2-dimension array into a table, so that it would be easy for me to debug any code i write.

I need the name of the given array so that i can output it as a title for the generated table.

Link to comment
Share on other sites

I would suggest that you use an associative array, ie.

$arr = array(
    'value1' => 1,
    'value2' => 2
);

echo $arr['value1'];

// outputs 1

or given your latest comment...

$arr = array(
    'tableName' => 'Table1',
    'tableData => array(
        'value1' => 1
     )
);
Edited by DarkKnight2011
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.