We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Correct way to get multiple values for same parameter name in GET request

Hi,

I am trying to send multiple values for the same parameter name in a GET request like this:

https://localhost/module?p=value1&p=value2

In my controller, I get the parameters with the following code:

$params = $this->request->getQuery();

And I obtain this:

array(2) { ["_url"]=> string(7) "/module" ["p"]=> string(6) "value2" }

So I guess that the getQuery function retrieves only the last value defined in the query.

Is there a simple way to retrieve an array of these values via Phalcon or do I have to change the format of my query and split it?



4.3k
Accepted
answer

I have found the answer to my question.

I modified my GET request like this:

https://localhost/module?p[]=value1&p[]=value2

Now, I get this:

array(2) { ["_url"]=> string(7) "/module" ["p"]=> array(2) { [0]=> string(6) "value1" [1]=> string(6) "value2" } }