is there a way to nest brackets?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fgomez
Forum Commoner
Posts: 61
Joined: Mon Sep 26, 2005 11:23 pm
Location: Washington, DC

is there a way to nest brackets?

Post 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!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: is there a way to nest brackets?

Post 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.
fgomez
Forum Commoner
Posts: 61
Joined: Mon Sep 26, 2005 11:23 pm
Location: Washington, DC

Post 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:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply