2014-10-19 63 views
-1

我跟隨this tutorial。我有這個指令:如何檢索給定的JSON對象中的鍵的值?

$cursor = $collection->find(array("author" => "shreef")); 
foreach ($cursor as $document) { 
    print_r($document) 
} 

使用的print_r被顯示物體的結構形式返回。

Array 
(
    [title] => cat with a hat 
    [content] => once upon a time a cat with a hat ... 
    [_id] => MongoId Object 
      (
       [$id] => 4ea2213af7ede43c53000000 
      ) 
) 

如果我想抓取標題的值,該怎麼辦?

回答

1

這是做你想做的嗎?

$cursor = $collection->find(array("author" => "shreef")); 
foreach ($cursor as $document) { 
    echo $document['title']; 
}