Passing a 2-dimensional array in an HTTP request

I am trying to create a simple API for a web service that I wrote. The problem I am facing is this: the form will present the user with any number of topics. This number will change for each database.

The user can select any number of topics presented, and later can also assign them a numerical value to describe the level of relevance.

What I need to do is pass a 2-dimensional array [themeid: theme value] to each webserivce for each selected theme.

I'm not sure how to do this using HTTP get or POST.

Thank any help!

+3
source share
2 answers

2- ? , , ? json:

[
    {
        "rating": 5, 
        "themeId": 1
    }, 
    {
        "rating": 3, 
        "themeId": 2
    }
]
+2

. json.

php-, , php- > json

php > $root = array();
php > $node = new stdClass();
php > $node->theme = "theme";
php > $node->value = "value";
php > $root[12] = $node;

print_r , , php.

php > print_r($root);
Array
(
    [12] => stdClass Object
        (
            [theme] => theme
            [value] => value
        )

)

json.

php > echo json_encode($root);
{"12":{"theme":"theme","value":"value"}}

, POST GET , json_decode() - .

+1

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


All Articles