简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM