-3

I want to display this json format through php....

xyz({
    "something": "something",
    "something": "link",
    "something": "",
    "something": "something",
    "something": "link",
    "items": [
   {
        "something": "something",
        "something": "link",
        "something": {  "m":"link"   },
        "something": "something",
        "something": " <p>something<\/p> ",
        "something": "something",
        "something": "something",
        "something": "something",
        "something": "something"
   },
   {
        "something": "something",
        "something": "link",
        "something": {    "m":"link"   },
        "something": "something",
        "something": " <p>something<\/p> ",
        "something": "something",
        "something": "something",
        "something": "something",
        "something": "something"
   },

    ]
})
H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
kushagra
  • 25
  • 6

3 Answers3

3

Maybe this will help you:

print(json_encode($yourarray));
H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
Marta Tenés
  • 2,102
  • 1
  • 13
  • 22
3

In that case you should use JSON encode:

print(json_encode($xyz));
pguetschow
  • 5,176
  • 6
  • 32
  • 45
3

You can use the following code:

    <?php
    $arr = ['1','2']; //Your array
    header('Content-Type: application/json'); //See my explanation
    echo json_encode($arr);
    ?>

Although it might not be required for other cases, if you are trying to create an API-like format which seems to me that you are, you need to set the Content-Type header to application/json as well so that receiving party gets the correct format.

Acharya Anurag
  • 671
  • 6
  • 23