-2

In My Web Application I am Using Json. I Need to create following Format of Json File in PHP.

{
    "title": "A cool blog post",
    "clicks": 4000,
    "children": null,
    "published": true,
    "comments": [
        {
            "author": "Mister X",
            "message": "A really cool posting"
        },
        {
            "author": "Misrer Y",
            "message": "It's me again!"
        }
    ]
}
1
  • 3
    What have you tried so far? Any codeexamples? json_encode($array) might be just what you are looking for tho. - Please keep in mind that Stackoverflow is a Website where people help you, not do all the work for you. Commented Mar 24, 2016 at 9:34

2 Answers 2

1

Here is the solution:

  • Open Google
  • Type PHP JSON
  • hit Enter
  • Click the 1st result
  • Replace the values from PHP examples with json_encode with your own values
Sign up to request clarification or add additional context in comments.

Comments

0

json_encode will encode a PHP array as a JSON array.

As the exmaple on that link shows:

<?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

echo json_encode($arr);

// {"a":1,"b":2,"c":3,"d":4,"e":5}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.