Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中创建多数组Json文件_Php_Json - Fatal编程技术网

在PHP中创建多数组Json文件

在PHP中创建多数组Json文件,php,json,Php,Json,在我的Web应用程序中,我使用的是Json。我需要在PHP中创建以下格式的Json文件 { "title": "A cool blog post", "clicks": 4000, "children": null, "published": true, "comments": [ { "author": "Mister X", "message": "A really cool postin

在我的Web应用程序中,我使用的是Json。我需要在PHP中创建以下格式的Json文件

{
    "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!"
        }
    ]
}
以下是解决方案:

  • 打开谷歌
  • 键入PHP JSON
  • 按回车键
  • 单击第一个结果
  • 将PHP示例中的值替换为您自己的值
    • 将PHP数组编码为JSON数组

      正如该链接上的exmaple所示:

      <?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}
      

      到目前为止您尝试了什么?有代码示例吗?也许正是你想要的请记住,Stackoverflow是一个人们帮助你的网站,而不是为你做所有的工作。