jini jini - 2 months ago 8
PHP Question

Convert a MongoCursor from ->find() to an array

$jokes = $collection->find();


How do I convert
$jokes
into an array?

Answer

You can use PHP's iterator_to_array function, as suggested in example 1 of the MongoCursor docs:

$jokes = $collection->find();
$jokesArray = iterator_to_array($jokes);