0

I have an array and I want to convert array to json with php.

But my json_encode() function is that output:

$array = [
     'styles' => ['style'=>[]]
     ]; 


 {
     "stlyes":{
       "style":{
             0:{},
             1:{}
      }

}} 

//But it must be such
 {
     "stlyes":{
       "style":{},
       "style":{}

}}
user2342558
  • 4,717
  • 5
  • 27
  • 50
slddzz
  • 9
  • 2

1 Answers1

0

I tried that format

$arr = [
        'styles'=>[
            'style'=>['name'=>'TRENCH','price'=>20.0],
            'style'=>['name'=>'JACKET','price'=>78.0],
        ]
    ];

And that output:

    Array
(
    [styles] => Array
        (
            [style] => Array
                (
                    [name] => JACKET
                    [price] => 78
                )

        )

)

json_encode($arr) :

{
  "styles": {
    "style": [
      {
        "name": "TRENCH",
        "price": 20
      },
      {
        "name": "JACKET",
        "price": 78
      }
    ]
  }
}

But I want that format:

    {
     "stlyes":{
       "style":{},
       "style":{}

}}
slddzz
  • 9
  • 2