469,927 Members | 1,887 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

array $_GET

Sen
Hi,

why:

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

Doesn't work?
sen
Feb 27 '07 #1
4 10536
Sen schrieb:
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;
}
Feb 27 '07 #2
On Tue, 27 Feb 2007 14:08:10 +0100, Mike Roetgers
<mi******@informatik.uni-bremen.dewrote:
Sen schrieb:
>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/
Feb 27 '07 #3
Rik
On Tue, 27 Feb 2007 23:22:55 +0100, OmegaJunior
<om*********@spamremove.home.nlwrote:
On Tue, 27 Feb 2007 14:08:10 +0100, Mike Roetgers
<mi******@informatik.uni-bremen.dewrote:
>Sen schrieb:
>>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
Mar 1 '07 #4
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:
Hi,

why:

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

}

Doesn't work?
sen

Mar 1 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Abhishek Srivastava | last post: by
9 posts views Thread by gl | last post: by
9 posts views Thread by Chris | last post: by
3 posts views Thread by Fernando Rodríguez | last post: by
2 posts views Thread by Patrick | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.