Is there a way that I can name a "variable" that I want to set, when
that "variable" might be an array element? For example:
<?php
function setMe ($varName, $varVal) {
$greeting = "Hello";
$aRay = array("there", "Fred");
$$varName = $varVal;
output( "$greeting " . join(", ", $aRay));
}
setMe ("greeting", "Goodbye"); // => Goodbye there, Fred
setMe ("aRay[1]", "Mom"); // I'd like: Hello there, Mom
?>
Thanks,
Csaba Gabor from Vienna
The actual situation is more complicated. I have a class, and the
variables in question are members of the class. Even if I do eval, I
don't get a reference to the thing that needs changing and if I can't
eval $varVal because $varVal will be an object.
that "variable" might be an array element? For example:
<?php
function setMe ($varName, $varVal) {
$greeting = "Hello";
$aRay = array("there", "Fred");
$$varName = $varVal;
output( "$greeting " . join(", ", $aRay));
}
setMe ("greeting", "Goodbye"); // => Goodbye there, Fred
setMe ("aRay[1]", "Mom"); // I'd like: Hello there, Mom
?>
Thanks,
Csaba Gabor from Vienna
The actual situation is more complicated. I have a class, and the
variables in question are members of the class. Even if I do eval, I
don't get a reference to the thing that needs changing and if I can't
eval $varVal because $varVal will be an object.
Comment