views:

35

answers:

1

i got several variable. One is variable string, object, and array.

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

i want to create a new array with its variable name as key before send it to as function parameter with it's first line use extract function. the multi_array will be like this

multi_array = array (

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

i use key to get the name of array and getclass to get the name of object. But how i got the name of the string variable ?

function i_do_extract($multi_array) {
   extract($multi_array);
   // Do Rest
}
+1  A: 

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