|
Posted by Jerry Stuckle on 09/29/05 12:01
Giovanni wrote:
> Hi! I've an array of string like this:
>
> $arraystring["name"]="John";
> $arraystring["age"]="50";
> $arraystring["work"]="teacher";
>
> $arraystring is global variable.
>
> I'm trying to code a function that get a string as parameter and print
> the relative arraystring's value.
>
> function printArrayStr($key)
> {
> global $arraystring;
> echo $arraystring["$key"];
> }
>
> What do I wrong?! :(
>
> tnx, people!
>
First of all, don't use globals. If you want to pass it to the
function, pass it to the function. As a global, $arraystring could be
changed anywhere, and you'll have a hard time figuring out what the
problem is.
But are you sure this is *exactly* like you have it in your code? For
one thing, you shouldn't have quotes around $key as the index.
But you never told us what your problem is, so it's impossible to tell
you what the cause is. For instance, Enable all error reporting and
display errors - do you get any error messages? What's actually in
$arraystring and $key in the function?
And finally - I agree - this is probably one of the $*worst* ways to
handle multiple languages.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|