More than one value in the same GET parameter

Asked

Viewed 47 times

0

It is possible to assign more than one value in the same GET parameter via http, as if I had passed an array in this parameter?

For example: http://www.exemplo.com/buscar?campos=nome,data,endereco

Edit1: The application that will receive the request is developed in Laravel, if this influences.

  • 1

    https://stackoverflow.com/a/3061292

2 answers

3


Yes, it is possible to pass this way, you can use the explode() then to get each value individually.

$campos = explode(",", $_GET["campos"]);

You can also pass as an array

// ?campos[]=nome&campos[]=data&campos[]=endereco
$campos = $_GET["campos"]; // já vai ser um array

2

It is possible yes, just put [] after the parameter name, it will automatically mount the array, the parameters would look like this:

?fields[]=fieldname[]=data&fields[]=address

By making a var_dump($_GET), the return will be:

array(1) { ["fields"]=> array(3) { [0]=> string(4) "name" [1]=> string(4) "date" [2]=> string(9) "address" } }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.