0

I have an array with structure like - (checked with print_r statement)

Array
(
    [0] => Array
        (
            [ads] => 343443543
            [ad_name] => Cup
            [cup_id] => 8869327
            [web_url] => www.yahoo.com
            [title] => Array
                (
                    [0] => title1
                    [1] => title2
                    [2] => title3
                    [3] => title4
                    [4] => title5
                )

            [description] => Array
                (
                    [0] => desc1
                    [1] => desc2
                    [2] => desc3
                )

            [new_title] => new_title1
        )

    [1] => Array
        (
            [ads] => 2325334
            [ad_name] => Cup
            [cup_id] => 8869327
            [web_url] => www.google.com
            [title] => Array
                (
                    [0] => title1
                    [1] => title2
                    [2] => title3
                    [3] => title4
                    [4] => title5
                )

            [description] => Array
                (
                    [0] => desc1
                    [1] => desc2
                    [2] => desc3
                )

            [new_title] => new_title1
        )
)

When I use json_encode, it is returning with some object format like -

{"0":{"ads":"343443543","ad_name":"Cup","cup_id":"8869327","web_url":"www.yahoo.com","title":["title1","title2","title3","title4","title5"],"description":["desc1","desc2","desc3"],"new_title":"new_title1"},"1":{"ads":"2325334","ad_name":"Cup2","cup_id":"8869327","web_url":"www.google.com","title":["title1","title2","title3","title4","title5"],"description":["desc1","desc2","desc3"],"new_title":"new_title2"}

Instead, I want to have json string to be -

[{"ads":"343443543","ad_name":"Cup","cup_id":"8869327","web_url":"www.yahoo.com","title":["title1","title2","title3","title4","title5"],"description":["desc1","desc2","desc3"],"new_title":"new_title1"},{"ads":"2325334","ad_name":"Cup2","cup_id":"8869327","web_url":"www.google.com","title":["title1","title2","title3","title4","title5"],"description":["desc1","desc2","desc3"],"new_title":"new_title2"}]

I have another array variable for which it is showing correct json format. Now, sure what's wrong here.

Any help is appreciated.

SandyK
  • 465
  • 1
  • 9
  • 28

1 Answers1

1

Try json_encode(array_values($data)) ?

David Goodwin
  • 4,184
  • 1
  • 22
  • 12