Skip to content

Instantly share code, notes, and snippets.

View domainoverflow's full-sized avatar

DomainOverflow.com domainoverflow

View GitHub Profile
@domainoverflow
domainoverflow / MongoDbCursorToPhpArrayAtALowerCost.php
Last active July 26, 2018 13:31
Convert MongoDB cursor to PHP Array at a lower cost. Instead of using cursor.toArray() (at the time of the query ) which can be heavy, the function below allows you to convert MongoDB\Cursor directly into a PHP Array locally, improving the overall performance of the Iteration between PHP and MongoDB.
public function convertMongoDBCursorToArray($dbcursor) {
$counter=0; $x=0;
$finalarray = Array() ; $convertedarray=Array() ;
foreach($dbcursor as $document) { $finalarray[$counter]=$document; $counter++;}
$finalarray=array_values($finalarray);
$thissize = count($finalarray);
$counter=0;