Reply to Re: accessing arrays

Your name:

Reply:


Posted by ZeldorBlat on 11/23/05 07:21

>>Name the list "var[]" instead of "var"...
>Thanks for contributing a reply, but I cannot decode your answer. And I
>still haven't found the answer to my situation.
>
>I'm not naming anything 'var' or 'var[]'/

Sure you are. You provided the following URL:
mypage.php?var=2&var=4&var=5 In this case, you've named all three
variables var. What would you expect the following code to output:

$x = 2;
$x = 4;
$x = 5;
echo $x;

This will echo 5 because you've given a new value to $x on the second
line, and overwrote it again on the third line. The same thing happens
with your URL. The last value of var overwrites the first and second
value. As such, you get var = 5 on mypage.php.

You can do one of two things here: either give each variable a
different name, like mypage.php?var1=2&var2=4&var3=5 in which case
you'd refer to them as $_GET['var1'], $_GET['var2'], etc.

Alternatively you can make var an array in the URL and access it like
an array on mypage.php. For instance, your URL might look like this:
mypage.php?var[0]=2&var[1]=4&var[2]=5. On mypage.php, you can get to
those like this: $_GET['var'][0], $_GET['var'][1], etc.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация