0

when I print the array I created with php to the screen with the print_r function, it looks normal.

But when I convert it to json data with the json_encode function, the keys are lost. I tried a lot but couldn't find a solution.

Thank you in advance for your help. function -> print_r

 [1] => Array
        (
            [succes] => 1
            [title] => Test Title
            [0] => Array
                (
                    [0] => car
                    [1] => bus
                    [2] => a
                    [3] => b
                    [4] => c
                    [5] => d
                )

        )

Json function -> json_encode

{
"0": [
  "car",
  "bus",
  "a",
  "b",
  "c",
  "d"
],
“succes”: "1",
“Title”: “Test Title”
  }

3
  • JSON is key value oriented. So you should make [0] => Array something like 'data' => Array. Commented Sep 10, 2022 at 18:32
  • json_encode works as expected. You need to understand the difference between numeric arrays and associative arrays. Commented Sep 10, 2022 at 18:37
  • Solution: link Commented Sep 11, 2022 at 7:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.