The manual on “extract” shows you can extract an array like:
extract(array('one'=>1,'two'=>2));
into $one,$two…
But the extract function doesn’t return the variables. Is there a way to ‘globalize’ these variables? Maybe not using extract, but a foreach loop?
EDIT: (explanation about what I’m trying to achieve)
I have an array containing hundreds of output messages which I want to have accessible as variables efficiently. What I mean is that whenever I want to output a message, say:
$englishMessages = array('helloWorld'=>'Hello World');
$spanishMessages = array('helloWorld'=>'Hola Mundo');
'<span id="some">'. $helloWorld .'</span>';
The message would appear. The reason I’m doing it like this is so that users can change the language they’re viewing the website in, so something like:
”. $helloWorld .”;
would produce:
Hola Mundo!
Not exactly an answer to your question …but: Keep the array, don’t pollute the (global) variable namespace.
Some variations on the same theme:
or
You might also be interested in http://docs.php.net/gettext