【发布时间】:2014-08-20 19:38:55
【问题描述】:
我有一个像这样的 json 数组
{
"id":"1507593152797237",
"handle":"naveen",
"firstName":"bos",
"lastName":"Hello",
"email":"testnaveen.bos@gmail.com",
"pic":null,
"following":[
"123"
],
"followers":[
],
"groups":[
],
"blocking":[
],
"blockers":[
],
"postUnfollowing":[
],
"followingGroups":[
],
"likes":[
]
},
{
"id":"1234",
"handle":"naveesn.bos",
"firstName":"naveenbos",
"lastName":"boss",
"email":"naveen.boss@gmail.com",
"pic":null,
"following":[
"123"
],
"followers":[
],
"groups":[
11
],
"blocking":[
],
"blockers":[
],
"postUnfollowing":[
],
"followingGroups":[
],
"likes":[
],
}
我想从这个数组中删除不需要的项目,例如 followingGroups[]、blockers[]、blocking[]、
$response =array();
foreach ($user["followers"] as $follower) { $response[] = $this->mongologue->user('find', $follower); } echo json_encode($response);
我需要从 $response 中取消设置不需要的东西,意思是在 Groups[]、blockers[]、blocking[] 之后删除这些东西,请帮忙。
【问题讨论】:
-
上面的json对象数组是由json_encode($response)创建的吗?
-
@ShaunakShukla 是的,这个 json 对象是从 json_encode($response) 创建的
-
那么你可以在json_encode($response);之前使用Suman Biswas的答案但在循环中!或者您可以在添加到 $response[]! 之前在当前的 foreach 循环中保留条件