0

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');

4
  • why not make a seperator like this: myserver.com/myscript.php?param=55311_352213_6214 and then explode it? Commented Dec 3, 2014 at 9:12
  • I am very beginner with php, how to explode that? Commented Dec 3, 2014 at 9:12
  • $paramArr = explode('_', $_GET['param']) Commented Dec 3, 2014 at 9:14
  • thank you. I didn't know it's that easy Commented Dec 3, 2014 at 13:25

2 Answers 2

2

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
}
Sign up to request clarification or add additional context in comments.

3 Comments

Back in the mists of time I remember being told that such indexing wasn't strictly speaking allowed in URLs, though PHP seems to handle it OK..? And should the square brackets be URL encoded?
@RobBaillie no you do not need to encode it, just put them as is: codepad.viper-7.com/…
?param[]=55311&param[]=352213&param[]=6214 it doesn't looks nice, i think this is better ?param=55311_352213_6214 but thank you anyway!
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.