[help] about the json format of php output

The array in

php is as follows:

array (size=2)
  0 => 
    array (size=2)
      0 => 
        array (size=4)
          "id" => int 1
          "fid" => int 0
          "title" => string "1" (length=12)
          "level" => int 9
      1 => 
        array (size=4)
          "id" => int 2
          "fid" => int 0
          "title" => string "2" (length=12)
          "level" => int 8
  1 => 
    array (size=2)
      0 => 
        array (size=4)
          "id" => int 11
          "fid" => int 1
          "title" => string "1" (length=12)
          "level" => int 0
      1 => 
        array (size=4)
          "id" => int 12
          "fid" => int 1
          "title" => string "2" (length=12)
          "level" => int 0

output using json_encode is as follows:

[
    [{
        "id": 1,
        "fid": 0,
        "title": "1",
        "level": 9
    }, {
        "id": 2,
        "fid": 0,
        "title": "2",
        "level": 8
    }],
    [{
        "id": 11,
        "fid": 1,
        "title": "1",
        "level": 0
    }, {
        "id": 12,
        "fid": 1,
        "title": "2",
        "level": 0
    }]
]

the format you want is

"0": [{
        "id": 1,
        "fid": 0,
        "title": "1",
        "level": 9
    }, {
        "id": 2,
        "fid": 0,
        "title": "2",
        "level": 8
    }],
"1": [{
        "id": 11,
        "fid": 1,
        "title": "1",
        "level": 0
    }, {
        "id": 12,
        "fid": 1,
        "title": "2",
        "level": 0
    }]
Apr.09,2021

has not written php, but you have got the result after json_encode. Just go through the array and reassemble it. The array sequence number can be used as the new element of the key, array in the west as value


json represents the array of the following table in the form of []; for example,

[
    '1'
    '2'
]

this is equivalent to

[
    0=>'1'
    9=>'2'
]

so the result you get is fine,

you use your variable name [0] to get the array that is your number

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36d84-34412.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36d84-34412.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?