Skip to content
Advertisement

PHP convert similar names variables to json

I’m getting via url querystring variables like:

myserver_state=1&myserver_running=2&myserver_mem=3

Currently i’m adding to an existing json like:

JavaScript

And i really want it like this:

JavaScript

I’m using this to load them:

JavaScript

Many thanks!

EDIT:

following comments i tried:

status.php?server1[current_state]=10

this actually works to:

JavaScript

Which is great, BUT, if i then want to add an element like this: status.php?server1[current_mem]=1

This actually REPLACES the whole server1

JavaScript

and i lose the already existing current_state

Advertisement

Answer

Just use multidimensional array within your URL like:

JavaScript

so easy script

JavaScript

will give you

JavaScript

of course, if required you can use also POST request with the same naming rules.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement