Dynamically handling GET variables?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

Dynamically handling GET variables?

Post by PhpDog »

I am sending dynamically created GET variables to a php page.

Usually I use:

$offset = $_GET['offset'];
$mortgage = $_GET['mortgage'];

to use the incoming GET variables.

My dynamically created incoming GET variables take the form:

t1=2,t2=4,t3=1,t4=7 etc.

Is there a way I can dynamically grab these for something like:

$t1 = $_GET['t1'] etc?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Dynamically handling GET variables?

Post by Christopher »

It should be with ampersands for URL params:

mysite.com?t1=2&t2=4&t3=1&t4=7
(#10850)
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

Re: Dynamically handling GET variables?

Post by PhpDog »

arborint wrote:It should be with ampersands for URL params:

mysite.com?t1=2&t2=4&t3=1&t4=7
Yes, I understand that. What I was fumbling to convey was that my variables follow a distinct sequence.
This is why I thought I may be able to 'automate' their capture.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Dynamically handling GET variables?

Post by John Cartwright »

PhpDog wrote:
arborint wrote:It should be with ampersands for URL params:

mysite.com?t1=2&t2=4&t3=1&t4=7
Yes, I understand that. What I was fumbling to convey was that my variables follow a distinct sequence.
This is why I thought I may be able to 'automate' their capture.
In this case where the number of elements is unknown you might want to use an array to be able to easily loop over the variables.

mysite.com?t[]=2&t[]=4&t[]=1&t[]=7

Code: Select all

foreach ($_GET['t'] as $key => $foo) {
   echo $key .':'. $foo .'<br />';
}
PhpDog
Forum Commoner
Posts: 58
Joined: Mon Jan 14, 2008 10:23 am

Re: Dynamically handling GET variables?

Post by PhpDog »

Many thanks to everyone who answered.
Post Reply