0

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
}
Rizier123
  • 58,877
  • 16
  • 101
  • 156
justjoe
  • 5,454
  • 9
  • 44
  • 64

1 Answers1

1

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.

Tim Green
  • 2,028
  • 1
  • 17
  • 19