Code Comments
Programming Forum and web based access to our favorite programming groups.Dear all, I have a question about multi-dimension array in PHP $m = 2; $def = "Hello"; $abc[$m] = $def; print "$abc[$m] \n"; This works and gives "Hello" as output. However, if I do this: $n = 3; $m = 2; $def = "Hello"; $ghi[$m][$n] = $def; print "$ghi[$m][$n] \n"; This gives me something strange, like "Array[2]" as output, but not "Hello". How can this be rectified to print out "Hello" as stored in $ghi[2][3] in this case? Thanks, LaBird (Benny). [Email: Please drop all numerals for the real email address.]
Post Follow-up to this message"LaBird" <wlcheung@hkucs1975.org> wrote in message
news:d7omdh$65h$1@webinfo.cs.hku.hk...
> Dear all,
>
> I have a question about multi-dimension array in PHP
>
> $m = 2;
> $def = "Hello";
> $abc[$m] = $def;
> print "$abc[$m] \n";
>
> This works and gives "Hello" as output.
>
> However, if I do this:
> $n = 3;
> $m = 2;
> $def = "Hello";
> $ghi[$m][$n] = $def;
> print "$ghi[$m][$n] \n";
>
print "{$ghi[$m][$n]} \n";
php is good at interpreting what you mean, but it's not perfect. Sometimes
you gotta help it, like by surrounding a multidimensional array reference by
{} parenthesis when it's inside of a string.
--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
eternal piste erection miuku gmail piste com
Post Follow-up to this messageLaBird schrieb:
> Dear all,
>
> I have a question about multi-dimension array in PHP
>
> $m = 2;
> $def = "Hello";
> $abc[$m] = $def;
> print "$abc[$m] \n";
>
> This works and gives "Hello" as output.
>
> However, if I do this:
> $n = 3;
> $m = 2;
> $def = "Hello";
> $ghi[$m][$n] = $def;
> print "$ghi[$m][$n] \n";
>
> This gives me something strange, like "Array[2]" as output,
> but not "Hello".
>
> How can this be rectified to print out "Hello" as stored in
> $ghi[2][3] in this case?
>
> Thanks,
> LaBird (Benny).
> [Email: Please drop all numerals for the real email address.]
>
>
Hello,
if you want to use array variables in strings try these alternatives:
print "{$ghi[$m][$n]} \n";
or
print $ghi[$m][$n]." \n";
cu Tobias
Post Follow-up to this messageThanks a lot!
Best Regards,
Benny (LaBird).
"tobi" <tobias_g@arcor.de> ???
news:429fecd0$0$14736$9b4e6d93@newsread4
.arcor-online.net ???...
> LaBird schrieb:
> Hello,
> if you want to use array variables in strings try these alternatives:
> print "{$ghi[$m][$n]} \n";
> or
> print $ghi[$m][$n]." \n";
>
> cu Tobias
Post Follow-up to this messageHi Kimmo,
Thanks a lot!
Best Regards,
Benny (LaBird).
"Kimmo Laine" <eternal.erectionN05P@Mgmail.com> ¦b¶l¥ó
news:_ZRne.1994$u74.941@reader1.news.jippii.net ¤¤¼¶¼g...
> print "{$ghi[$m][$n]} \n";
>
> php is good at interpreting what you mean, but it's not perfect. Sometimes
> you gotta help it, like by surrounding a multidimensional array reference
by
> {} parenthesis when it's inside of a string.
>
> --
> Welcome to Usenet! Please leave tolerance, understanding
> and intelligence at the door. They aren't welcome here.
> eternal piste erection miuku gmail piste com
>
>
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.