How foreach of PHP works with MongoDB Cursor?
<p>There are certain functions that we use from MongoDB driver like to iterate a cursor we can use "hasNext()" and "getNext()". But we can also use simple PHP's foreach to iterate cursor and we don't have to call the above methods.</p>

<p>My question is if foreach is simple PHP function, how does it work with MongoDB ? How does it fetches the records from cursor ? Does it internally use "cursor.forEach()" of MongoDB or does it internally runs "hasNext()" and "getNext()" ?</p>

<p>Any help would be greatly appreciated.</p>