Reply to Re: Array references by name

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация