Page 1 of 1

Passing arrays with GET

Posted: Tue Aug 13, 2002 7:08 pm
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?

Posted: Tue Aug 13, 2002 7:49 pm
by protokol
try this...

$engine = $_GET['engine'];

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

etc. etc.

Posted: Wed Aug 14, 2002 1:44 am
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

Posted: Wed Aug 14, 2002 4:05 am
by bastabob
Thanks , protokol and twigletmac. Your tips help.

My code works now and I learned useful idioms from you!

Posted: Wed Aug 14, 2002 8:53 am
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

Posted: Wed Aug 14, 2002 10:51 am
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

Posted: Wed Aug 14, 2002 1:34 pm
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