|
Posted by Janwillem Borleffs on 08/22/05 01:13
Csaba Gabor wrote:
> Is there a way that I can name a "variable" that I want to set, when
> that "variable" might be an array element?
>
You could try the following:
function setMe ($varName, $varVal) {
$greeting = "Hello";
$aRay = array("there", "Fred");
if (is_array($varName)) {
${$varName[0]}[$varName[1]] = $varVal;
} else {
$$varName = $varVal;
}
print( "$greeting " . join(", ", $aRay) . '<br />');
}
setMe ("greeting", "Goodbye"); // => Goodbye there, Fred
setMe (array('aRay', 1), "Mom"); // => Hello there, Mom
JW
[Back to original message]
|