How can I get the name of a variable?

I got several variables. One variable contains a string, one an object, and one an array.

$mystring = "hello im input";
$myobject = new userclass;
$myarray  = array ( 0 => 'zero', 1 => "one"); 

I want to create an array containing the variable names as key and the values as values, so I then can send this array to a function.

The expected result would be:

$multi_array = array (
    'mystring' => "hello im input",
    'myobject' => new userclass,
    'myarray'  => array ( 0 => 'zero', 1 => "one")
)

I use the key to get the name of the array and getclass() to get the name of the object. But how can I get the name of the variable?

function i_do_extract($multi_array) {
   extract($multi_array);
   // Do Rest
}

Answers


I don't know if this will help you, but you can use:

http://www.php.net/manual/en/function.get-defined-vars.php

To list defined variables. Remember PHP does support things like

$str = "test";
$test = "hmmm";
echo $$str;

Which would output hmmm.


Need Your Help

When Designing a BI Start Schema, Should Dimension Tables Use Only User-Friendly Attribute Values?

sql-server database-design business-intelligence cognos star-schema

I am designing the Dimension tables for my BI Start schema. I have already observed the value of user-friendly attribute values associated with each Dimension value, as these can be used quite rea...