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
https://forums.phpfreaks.com/topic/277747-function-to-get-array-name/
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.

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
     )
);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.