Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

问题描述

PHP在查询MongoDB数据,使用的是mongodb/mongodb扩展。查询的数据返回的是个对象,如何将它返回的结果给转为“下面期望返回结果”的数据格式?查询代码如下:

$items = $this->db->$collection->find($searchWhere);
    if (!empty($items)) {
        $collectionArray = $items->toArray()[0];
        $returnArray = [];
        foreach ($collectionArray as $key => $value) {
        $returnArray[$key] = $value;
    }
    return $returnArray;
}

return [];

当前返回数据格式


  "_id": {
    "$oid": "5f8141982d229018660b93f3"
  },
  "name": "韩爱华"
}

期望返回数据格式

{
  "id": "5f8141982d229018660b93f3",
  "name": "韩爱华"
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
567 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...