Page 1 of 1

is there a way to nest brackets?

Posted: Wed Apr 18, 2007 9:24 am
by fgomez
Normally I do this:

Code: Select all

$foo = $_GET['foo'] ;
echo $some_array[$foo] ;

Is there a way to skip that step and do something like this:

Code: Select all

echo $some_array[$_GET['foo'] ] ;

I know this doesn't work, but I wonder if there is a syntax that does.

Thanks!

Re: is there a way to nest brackets?

Posted: Wed Apr 18, 2007 9:27 am
by volka
fgomez wrote:

Code: Select all

echo $some_array[$_GET['foo'] ] ;

I know this doesn't work, but I wonder if there is a syntax that does.
This does work.

Posted: Wed Apr 18, 2007 9:36 am
by fgomez
That's weird.... I'd tried that before and got a syntax error. I must have made an error somewhere else in the page and misinterpreted the message. :oops:

Posted: Wed Apr 18, 2007 10:45 am
by RobertGonzalez
My philosophy... try until you cannot possibly try anymore, then ask.

That type of syntax can be used to levels that are far deeper than one dimension. I wouldn't suggest it, but it can be done.