Mandriospo
Mandriospo

Reputation: 41

Multiple HTTP GET parameters into array

I want to pass multiple parameters numbers via url like this:

http://myserver.com/myscript.php?param=55311&param=352213&param=6214

(it might be formatted with other way, this is only example)

Now, how to put these parameters (numbers) into array in php code? Like this:

$param = array('55311', '352213', '6214');

Upvotes: 0

Views: 647

Answers (2)

user4420255
user4420255

Reputation:

A little late, but currently I found this solution, maybe helpfull for other.

?params['number1']=12345&params['name1']='Hello'

In PHP I get this..

if(isset($_GET['params'])) {
    $params = (array) $_GET['params']; 
}

Use this variables a little bit tricky. Please hava a look at this array index "'number1'" with two kinds of string chars.

echo $params["'number1'"] // => 12345
echo $params["'name1'"] // => Hello

But I get a nice kind of documented array items.

Upvotes: 0

Kevin
Kevin

Reputation: 41885

You could use/format your url this way and turn it into a grouping index:

param[]=value

So this turns into:

http://myserver.com/myscript.php?param[]=55311&param[]=352213&param[]=6214

So in PHP, you could process them thru $_GET:

if(isset($_GET['param'])) {
    $param = $_GET['param']; // this in returns an array of those values
}

Upvotes: 2

Related Questions