I need a function like this:
$foo = "bar";
$arr['bar'] = "foo";
myfunc(array($foo,$arr['bar'])); // return array('foo','bar')
Any Ideas how to achieve this? Is this even possible in PHP?
I need a function like this:
$foo = "bar";
$arr['bar'] = "foo";
myfunc(array($foo,$arr['bar'])); // return array('foo','bar')
Any Ideas how to achieve this? Is this even possible in PHP?
You can get a variable from a string name like so:
$foo = "123";
$bar = "foo";
var_dump($$bar); // string(3) "123"
But as far as I'm aware you can't go the other way, to find a variable's name.
There should be no need to know a variable's name anyway. Use associative arrays where possible.
<?php
$foo = "bar";
$arr['bar'] = "foo";
echo $$arr['bar']; //returns bar
myFunc(array($foo,$$arr['bar']));
?>
that would work..