如何使用php代码创建对象的json数组?
但是我想要这样的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":"
{
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'];