user3225075
user3225075

Reputation: 373

fetch array from url via GET request

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

Upvotes: 0

Views: 138

Answers (1)

Kevin
Kevin

Reputation: 41885

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.

Upvotes: 1

Related Questions