Getting an array from a query string using PHP

( NOTE: This is a continuation of the previous question, How do I pass an array in a query string ? , where I asked about standard methods for passing arrays in query strings.)

Now I have some PHP code that should consume the specified query string. What formats of query string arrays does PHP recognize, and do I need to do anything to extract the array?

The following does not work:

Query String:

?formparts=[a,b,c]

PHP:

$myarray = $_GET["formparts"];
echo gettype($myarray)

result:

string
+1
source share
2 answers

The query string should look something like this:

?formparts[]=a&formparts[]=b&formparts[]=c
+3
source

, $_GET. ? .

, , .

$products = array();
// ... Add some checking of $_GET to make sure it is sane
....
// then assign..
$products = explode(',', $_GET['pname']);

.. . , , $_GET, , . .

0

Source: https://habr.com/ru/post/1606291/


All Articles