Re: incrementing a register global

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You try to increment value of a var! to change it name u have to add $i to 
it's name like this
foreach($i=1;$i<=$boxes;$i++){
  echo $_GET['name'].$i;
}

foreach ($_GET as $var_name=>$var_value)
    {
$i++;
echo $var_mane.$i;
}

if I correctly understand u
""Jay Blanchard"" <jay.blanchard@xxxxxxxxxxxxxxxxxxxxx> ???????/???????? ? 
???????? ?????????: news:C8F323573C030A448F3E5A2B6FE2070B0430C846@xxxxxxxxxx
[snip]
I dont know it this is possible, but here it goes.  Hopefully I cac
explain
it well enough for someone to understand.

I am posting data to a php script.  I have several variables that are
the
same except the number at the end is different.  So the url of the
called
script will be something like:

http://www.something.com/test.php?name1=Sam&name2=Bill&name3=Joe

On my script I am using substr() and strrchr() to get the number of last

variable:

$names = substr(strrchr($_SERVER['QUERY_STRING'],"&"),7,1);

I am then trying to run a loop to call each variable and just print it
on
the screen:

for($i=1;$i<=$boxes;$i++){
  echo $_GET['name'].$i;
}

This is where my problem is.  And I dont know if this is even possible,
but
if you look at the echo line in the loop I am trying to add the number
of $i
to the register global.  I dont get an error in doing this, but when I
run
the script I get the number of $i instead of the value of $_GET['name1']

Like I said, I hope I explained this good enough for someone to know
what I
am trying to do.  If anyone has any suggestions or comments about doing
something like this please let me know.
[/snip]

Your terminology is a little mixed-up, you are not dealing with a
'register global' you are dealing with a variable and an array. If you
will do this...

print_r($_GET); You will see am array. then you can do something like
this..(without the substring manipulation above)

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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux