I have the following code:
var_dump($cursor);
foreach($cursor as $obj) {
echo "<div class='item' id='" . $obj['_id'] . "'>";
echo "<span class='listnick'>" . $obj['nick'] . "</span>";
echo "</div>";
}
The result of var_dump is the following:
array(2) {
[0]=>
&array(9) {
["_id"]=>
object(MongoId)#9 (1) {
["$id"]=>
string(24) "50af8dcd9cc231534400000c"
}
["nick"]=>
string(6) "safari"
}
[1]=>
array(9) {
["_id"]=>
object(MongoId)#8 (1) {
["$id"]=>
string(24) "50af8dca9cc2315644000009"
}
["nick"]=>
string(6) "chrome"
}
}
so obviously the foreach should print out "safari" and "chrome", but the problem is really weird:
Sometimes it returns "safari" twice and omits "chrome", and viceversa for the other client. I tried putting the var_dump and the foreach loop near to be sure they are the SAME and there are no changes in the object between the two commands, but really I got no idea what's going on.
Any help? Thanks in advance.
&array(9) {. I am referring to & ( the reference). can you give the code where you fill the $cursor array? i can't seem to recreate this output, no matter what and how i try to set the referrence.foreach($cursor as &$obj) { $obj['whatever'] = "foo"; }Apparently, this is what modified it to be like this.