0

Am trying to fetch an array from url via get request but am unable to do that

This is my URL with values encoded

    http://example.com/q.php?sub[]=xyz&sub[]=wsq

this is how am trying to store the values in another array

    $sub= array();
    $sub[]= $_GET['sub[]'];

Am not getting any result but if I run my page by manually initializing the array am getting the desired result without any issue

1 Answer 1

1

No, just access it as $_GET['sub']; in turn, it'll return an array of values.

Then you could just iterate it just like any array:

foreach($_GET['sub'] as $sub) {
    echo $sub;
}

What it should look like.

Sign up to request clarification or add additional context in comments.

3 Comments

But it doesn't behave as an array . means if i use foreach loop then it gives a blank result
sorry sorry my mistake. i got the desired result. thanks a lot
@user3225075 yes it will behave like an array if you put them in a grouping name key parameter, check out what i mean codepad.viper-7.com/8PgIcw?sub[]=xyz&sub[]=wsq

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.