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 开发者_如何学JAVAobject. But how can I get the name of the variable?
function i_do_extract($multi_array) {
extract($multi_array);
// Do Rest
}
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
.
精彩评论