php-mongodb: In PHP, how do I fetch an array stored in monogdb?
Can somebody please tell me where/what I'm doing it wrong and how the conversion should take place? I'm new to PHP and MongoDB so please excuse my naivety...
This is my document 开发者_如何学Pythonin mongo:
{ "_id" : "x", "links" : [1,2,3] }
In PHP, I do this:
foreach($cur as $obj)
echo $obj['_id'] . "-->" . $obj['links']
My output is:
x-->Array
instead of this:
x-->1,2,3
Thanks in advance!
Just to add clarification to the above answer.. what he's doing is really taking an array and casting it into a string with a ',' as a separator.. since the $obj is coming down as an array you would need to cycle through it (unless you're fine displaying it as such).
foreach($obj['links'] as $link){
//do something
}
This way you're keeping it in an array format rather than using an operation to cast it to a string.
Try this:
echo $obj['_id'] . "-->" . implode(',',$obj['links']);
精彩评论