0

I have problems to create the correct JSON form in PHP.

My JSON so far (i marked # wrong things):

    {
    "pools": { #this bracket should be [
        "1": {
            "pool-id": "1",
            "pool-name": "pool-nameX",
            "real-estates": { #this bracket should be [
                "1": {
                    "object-id": "idX",
                    "object-name": "nameX",
                    "object-description": "descX",
                    "object-type": "typeX",
                    "wdata": {
                        "2016": [162.68]
                    }
                }
            } #this bracket should be ]
        }
    } #this bracket should be ]
}

That's my PHP code:

$my_values = array();

$my_values["pools"]["1"] = array('pool-id'=>"1",'pool-name'=>"pool-nameX");

$my_values["pools"]["1"]["real-estates"]["1"] = array('object-id'=>"1",'object-name'=>"nameX",'object-description'=>"descX",'object-type'=>"typeX");

$my_values["pools"]["1"]["real-estates"]["1"]["wdata"]["2016"] = $array_with_values; #example 162,68

I tested some variants with array_push and other one but for some reasons i have problems to get this work.

Hopefully someone could bring me an example of how to create the one i need.

x-thx in advance!

user3882511
  • 125
  • 1
  • 10
  • Instead of `["pools"]["1"]` you can either use `["pools"][]` or `["pools"][0]` – Nigel Ren Nov 15 '18 at 21:08
  • ok. that means i was on the right way, but i'm not able to use for example ["pools"][2] as that means ["pools"][0], ["pools"][1] have to be available but in my case they're not. And that was my cause of the problem. It has to start with ["pools"][0] or ["pools"][]. Am i wrong, can there be a ["pools"][2] without ["pools"][0]? – user3882511 Nov 16 '18 at 17:51

0 Answers0