0

I tried to get the parameters h1 and h2 from the following url. However, when I used the code to get the values from the $_GET['params'], the print_r displayed only h2. How will I get all values "h1 and h2" ?

https: //localhost/mysite.com/mypage/index/?params=h1&params=h2

The code I tried to use for getting the parameters.

if(!empty($_GET['params'])){
    foreach ($_GET as $params){
     print_r($param);
    }
4
  • 1
    You should have both the parameters with different names. Commented May 22, 2017 at 10:57
  • https: //localhost/mysite.com/mypage/index/?params1=h1&params2=h2 .. you should pass variable like this.. (params1,params2) Commented May 22, 2017 at 10:58
  • Possible duplicate of How to get the values of check boxes in a group with PHP? Commented May 22, 2017 at 11:08
  • use array of params[] , Commented May 22, 2017 at 11:47

1 Answer 1

3

PHP overwrites GET paramaters with the same name, unless you use the [] syntax to generate an array.

So your URL must look like this, if you want this to work in PHP:

...?params[]=h1&params[]=h2
Sign up to request clarification or add additional context in comments.

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.