这是我的剧本
$terms = ['username' => $uri];
$user = $collection->findOne($terms);
结果
array (size=4)
'_id' =>
object(MongoId)[29]
public '$id' => string '4ff6e96bb0b4599016000006' (length=24)
'username' => string 'me' (length=10)
'name' => string 'Yes, It's me!' (length=16)
获取姓名
$name = $user['name'];
但是,我怎样才能获得$user['_id']
?
我尝试$user['_id']
不工作
请帮忙。感谢
更新
$user['_id']->{'$id'}
答案 0 :(得分:6)
$user['_id']->{'$id'}
没有必要和丑陋,您可以简单地将其转换为字符串以获取ID $id = (string)$user['_id'];