PDA

View Full Version : Multidimensional array


fstrnu
08-08-2004, 04:57 PM
This...

print"$Overall_Name[$place][$i]";

... displays this...

Array[1]

Why won't it show the value. I need to reference a specific value in a multidimensional array in this should work, right?

And, yes, I know the array is setup properly because I can traverse it via the foreach function.

Many thanks in advance!

raf
08-08-2004, 08:48 PM
the value itself is probably an array, so it's a 3D array

(so for instance $Overall_Name['avariable'][5] could be array('1','2') or so.)

Do a

print_r($Overall_Name);

and then look at the pagesource in your brawser. You'll see the array nicely structured.

firepages
08-09-2004, 01:46 AM
I think in this case print is printing... $Overall_Name[$place] .'['.$i.']'; which is indeed Array[1]

Braces will `cure` this though they are not needed if you do not use quotes .


<?
/*lose the quotes*/
print $Overall_Name[$place][$i];
/*or use braces*/
print "blah blah {$Overall_Name[$place][$i]} blah";
?>

raf
08-09-2004, 07:25 AM
I think in this case print is printing... $Overall_Name[$place] .'['.$i.']'; which is indeed Array[1]
Why do you think that ?
I don't see any reason why it would do that + that would probably just give an error.

Not using quotes would indeed in any case be better?

firepages
08-09-2004, 08:37 AM
Because PHP does not parse multidimensional arrays (nor I think object properties etc) within stings unless told otherwise , it 'sees' $Overall_Name[$place] , and prints that, (Array), then 'sees' [$i] , as an opening bracket , the variable $i then the closing bracket , it can't 'see' the array is multidimensional until put in {braces}

As you say, without the quotes its treated as expected and is the best thing to do anyway.

raf
08-09-2004, 08:42 AM
learned something new today :thumbsup:

since i always concatenate my strings and variables, i never came across this. thanks firepages.