How foreach of PHP works with MongoDB Cursor? -


there functions use mongodb driver iterate cursor can use "hasnext()" , "getnext()". can use simple php's foreach iterate cursor , don't have call above methods.

my question if foreach simple php function, how work mongodb ? how fetches records cursor ? internally use "cursor.foreach()" of mongodb or internally runs "hasnext()" , "getnext()" ?

any appreciated.

the mongocursor class implements iterator interface. so, foreaching cursor, same thing calling $cursor->next(), checking $cursor->valid() , getting value $cursor->current() (repeat until valid false). $key => $value format gets value of $cursor->key().

it internal runs not running "hasnext()", "getnext()", etc. runs standard methods abstractly described in iterator interface.

sorry captiousness, foreach not "simple php function"; it's language construct. i've found explanations the difference here on stack overflow.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -