Search code examples
phpjsonbackslash

Php how to add backslash inside array of strings


I have a below array:

 Array
    (
        [0] => CLICK
        [1] => CSC
    )

After json_encode I got below one.

"["CLICK","CSC"]"

How to convert this into "[\"CLICK\",\"CSC\"]" this.

Any one help.


Solution

  • Some info was missing which I got after discussion.

    They are manually replacing a lot of characters before returning json. Out of them they also include [ => "[ and ] => ]" due to their backend implications.

    A simple json_encode was solution for this along with skipping those character replacement for specific this key.