How to send array values ​​via url in PHP?

how to send an array via url in php?

I have an array of product identifiers in which I want to use this identifier through the URL, because I need osCommerce in which I work, how can I do this?

Usually, osCommerce asks for the insertion of a single product, which, in turn, returns me the product identifier, which I pass to the URL, and loads it into the shopping cart, which shows this added product, but now I have several products added on the first page with different product identifiers created, and I have to display these products the same way they are displayed in genaral, for which I will need all these identifiers created here in the URL

+3
source share
7 answers

Your search is http_build_query () .

Example from php.net:

$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'hypertext processor');

echo http_build_query($data);
// foo=bar&baz=boom&cow=milk&php=hypertext+processor

echo http_build_query($data, '', '&');
// foo=bar&baz=boom&cow=milk&php=hypertext+processor
+9
source
?

arr [] = abc & arr [] = pqr & arr [] = hoq & arr [] = xxx

+7
source

, , json_encode (php json) php. urlencode URL-. json_decode. json, . , .

+3

serialize() ?a[]=1&a[]=val2&someOtherArg=val. $_GET, :

array(
    'a' => array(
        0 => '1',
        1 => 'val2',
    ),
    'someOtherArg' => 'val'
)

, , , , ~ 2k . ()

+1

POST-, PHP:

<input type="text" name="myArray[]" value="A">
<input type="text" name="myArray[]" value="B">
<input type="text" name="myArray[]" value="C">

GET, explode:

page.php?myData=A,B,C,D

...

$myArray = explode(',', $_POST['myData']);
0

, http_build_query(), :

http://www.example.com/?pid[]=1&pid[]=2&pid[]=3 ...

, .

0

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


All Articles