For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > June 2005 > Multi Dimension Array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Multi Dimension Array
LaBird

2005-06-03, 3:55 am

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.]


Kimmo Laine

2005-06-03, 3:55 am

"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


tobi

2005-06-03, 3:55 am

LaBird 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
LaBird

2005-06-03, 8:55 pm

Thanks 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



LaBird

2005-06-03, 8:55 pm

Hi 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
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com