Passing arrays with GET

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
bastabob
Forum Newbie
Posts: 2
Joined: Tue Aug 13, 2002 7:08 pm
Location: Manila, Philippines

Passing arrays with GET

Post by bastabob »

Am learning PHP and my first post here.

I'm having problem passing in array variables with $_GET[]:

Code: Select all

echo $_GETї'engineї0]'];
echo $_GETї'engineї1]'];
show no values.

I pass it from a form with

Code: Select all

<SELECT NAME="engine&#1111;]" MULTIPLE>
Is there any constraints with nested arrays and Superglobals causing this?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

try this...

$engine = $_GET['engine'];

echo $engine[0];
echo $engine[1];

etc. etc.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try echoing out the entire contents of the $_GET array:

Code: Select all

echo '<pre>';
print_r($_GET);
echo '</pre>';
so you can see exactly what's in it.

Mac
bastabob
Forum Newbie
Posts: 2
Joined: Tue Aug 13, 2002 7:08 pm
Location: Manila, Philippines

Post by bastabob »

Thanks , protokol and twigletmac. Your tips help.

My code works now and I learned useful idioms from you!
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Concerning the below,
$engine = $_GET['engine'];
another option is to assign by reference. As such...

Code: Select all

$engine = &$_GET&#1111;engine];
In this way, $engine isn't a copy of $_GET[engine], but instead a pointer (in a sense) back to it. The advantage is that you aren't using additional memory to hold the same information under a different name. Now this may not make much of difference performance wise, but if your site were to really start getting tons of hits, then you do whatever you can to increase performance here and there. This is just one way that can help in some circumstances.

However, be mindful that whatever changes are made to $engine will also be made to $_GET[engine]. Check out the manual on it. It'll give you some good info on this topic.

Later on,
BDKR
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

there are tons of options .. another is this


echo $_GET['engine'][0];
echo $_GET['engine'][1];

it's all a matter of what you want to use
User avatar
sam
Forum Contributor
Posts: 217
Joined: Thu Apr 18, 2002 11:11 pm
Location: Northern California
Contact:

Post by sam »

yet another way is to you some array functions:

Code: Select all

do&#123;
  echo current($_GET&#1111;'sam']);
&#125;while(next($_GET&#1111;'sam']));
Cheers Sam
Post Reply