Connecting Tech Pros Worldwide Help | Site Map

array $_GET

  #1  
Old February 27th, 2007, 12:55 PM
Sen
Guest
 
Posts: n/a
Hi,

why:

$n = count($_GET);
for($i=0; $i<$n; $i++)
{
echo $_GET[$i]
}

Doesn't work?
sen
  #2  
Old February 27th, 2007, 01:15 PM
Mike Roetgers
Guest
 
Posts: n/a

re: array $_GET


Sen schrieb:
Quote:
Hi,
>
why:
>
$n = count($_GET);
for($i=0; $i<$n; $i++)
{
echo $_GET[$i]
}
>
Doesn't work?
sen
If you open index.php?test=hallo, then you can access the value with
$_GET['test'].
Your loop now tries to echo $_GET[0] for example, but you need to echo
$_GET['test'] in order to see anything. :-)

If you want to walk through an array, use
foreach ($array as $value)
{
echo $value;
}
  #3  
Old February 27th, 2007, 10:35 PM
OmegaJunior
Guest
 
Posts: n/a

re: array $_GET


On Tue, 27 Feb 2007 14:08:10 +0100, Mike Roetgers
<mikeroet@informatik.uni-bremen.dewrote:
Quote:
Sen schrieb:
Quote:
>Hi,
> why:
> $n = count($_GET);
>for($i=0; $i<$n; $i++)
>{
> echo $_GET[$i]
>}
> Doesn't work?
>sen
>
If you open index.php?test=hallo, then you can access the value with
$_GET['test'].
Your loop now tries to echo $_GET[0] for example, but you need to echo
$_GET['test'] in order to see anything. :-)
>
If you want to walk through an array, use
foreach ($array as $value)
{
echo $value;
}
The difference can be found in indexed arrays (using numbers) or
associative arrays (using texts). Using foreach() this difference is
overcome.



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
  #4  
Old March 1st, 2007, 03:45 AM
Rik
Guest
 
Posts: n/a

re: array $_GET


On Tue, 27 Feb 2007 23:22:55 +0100, OmegaJunior
<omegajunior@spamremove.home.nlwrote:
Quote:
On Tue, 27 Feb 2007 14:08:10 +0100, Mike Roetgers
<mikeroet@informatik.uni-bremen.dewrote:
>
Quote:
>Sen schrieb:
Quote:
>>Hi,
>> why:
>> $n = count($_GET);
>>for($i=0; $i<$n; $i++)
>>{
>> echo $_GET[$i]
>>}
>> Doesn't work?
>>sen
>>
>If you open index.php?test=hallo, then you can access the value with
>$_GET['test'].
>Your loop now tries to echo $_GET[0] for example, but you need to echo
>$_GET['test'] in order to see anything. :-)
>>
>If you want to walk through an array, use
>foreach ($array as $value)
>{
> echo $value;
>}
>
The difference can be found in indexed arrays (using numbers) or
associative arrays (using texts). Using foreach() this difference is
overcome.
Yup.

If you really, really want to do it the hard way:

$n = count($_GET);
for($i = 0;$i < $n;$i++){
echo reset(array_slice($_GET,$i,1));
}

But that's just crazy.... foreach it is :P.
--
Rik Wasmus
  #5  
Old March 1st, 2007, 09:45 PM
BKDotCom
Guest
 
Posts: n/a

re: array $_GET


99% likely that $_GET's keys aren't numeric

use this
foreach ( $_GET as $k =$v )
echo $v.' = '.$k;

or
$keys = array_keys($_GET);
foreach ( $keys as $k )
echo $_GET[$k];

etc...


On Feb 27, 6:40 am, Sen <s...@wp.plwrote:
Quote:
Hi,
>
why:
>
$n = count($_GET);
for($i=0; $i<$n; $i++)
{
echo $_GET[$i]
>
}
>
Doesn't work?
sen

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
array in $_GET ... dude answers 8 June 19th, 2006 09:55 AM
How to pass array names to function parameters ? tony@tony.com answers 10 April 18th, 2006 02:25 PM
Using header("Location:...". How to pass over array variable? Dave Smithz answers 13 July 17th, 2005 12:17 PM
PHP5 and Global Array ($_GET) gf answers 5 July 17th, 2005 01:45 AM