Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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,但是我想要这样的json格式 { user_id: [3] "1234", "31332", "12412" profile_image_url: [3] "localhost/1234.com", "localhost/2345.com", "localhost/3456.com" } 您希望对阵列进行稍微不同的组织 试试这个 "user_id":[ { "id":"1234", "url":"

但是我想要这样的json格式

{
user_id: [3]

  "1234",
  "31332",
  "12412"


profile_image_url: [3]

      "localhost/1234.com",
      "localhost/2345.com",
      "localhost/3456.com"

}

您希望对阵列进行稍微不同的组织

试试这个

"user_id":[
    {
        "id":"1234",
        "url":"localhost/1234.com"
    },
    {
        "id":"1234",
        "url":"localhost/1234.com"
    },
    {
        "id":"1234",
        "url":"localhost/1234.com"
    }
]
所有内容都应该在user_id中,然后通过将$i放在$id和$url之前,您将根据需要对它们进行分组

"user_id":[
    {
        "id":"1234",
        "url":"localhost/1234.com"
    },
    {
        "id":"1234",
        "url":"localhost/1234.com"
    },
    {
        "id":"1234",
        "url":"localhost/1234.com"
    }
]
$row_array['user_id'][$i]['id']=explode(',',$row['user_id']);
$row_array['user_id'][$i]['url']=$row['profile_image_url'];