Search code examples
phpparametersget

How do i add a query string to $GET function


I have $GET function that by default send out a request to get 30 items back

$transactions = $MK->getTransactions($_GET)

It will go to the header as following

transactions?&page=1&per_page=30

And from the API provider module i found this line

 if (!empty($params['per_page'])) {
            $request_params['per_page'] = (int) $params['per_page'];
        }

SO my question is how to add the param to the $_GET

Right now when it goes out just as $transactions = $MK->getTransactions($_GET)

the request itself will go out as /transactions?&page=1&per_page=30

But i need to change the per_page value to smth else.


Solution

  • So you have smth like:

    $transactions = $MK->getTransactions($_GET)
    

    Whiich leads you to the following path:

    /transactions?&page=1&per_page=30
    

    But you want to change the value of one parameter in $_GET?

    First, from you example, if you'd print $_GET, you would see:

    Array
    (
        [page] => 1
        [per_page] => 30
    )
    

    So do smth like:

    $parameters = $_GET;
    $parameters["per_page"] = 123; 
    

    And than:

    $transactions = $MK->getTransactions($parameters);
    

    which will result in changed number per page.