@@ -53,7 +53,8 @@ To learn how to create a free MongoDB Atlas cluster and load the sample datasets
53
53
Access Cursor Contents Iteratively
54
54
----------------------------------
55
55
56
- To iterate over the contents of a ``MongoDB\Driver\Cursor`` instance, use a ``foreach`` loop.
56
+ The ``MongoDB\Driver\Cursor`` class implements the ``Iterator`` interface, so you
57
+ can use a ``foreach`` loop to iterate through its contents.
57
58
58
59
The following example uses the ``MongoDB\Collection::find()`` method to retrieve all documents
59
60
in which the ``name`` field value is ``'Dunkin' Donuts'``. It then prints each document from the
@@ -111,8 +112,14 @@ Retrieve All Documents
111
112
application memory, your program will crash. If you expect a large result
112
113
set, :ref:`access your cursor iteratively <php-cursors-iterate>`.
113
114
114
- To retrieve all documents from a cursor, convert the cursor into an array. The following
115
- example calls the ``toArray()`` method on a cursor to store its results in an array:
115
+ To retrieve all documents from a cursor, convert the cursor into an array by using
116
+ either of the following methods:
117
+
118
+ - ``MongoDB\\Driver\\Cursor::toArray()``: Call on a ``MongoDB\Driver\Cursor`` object
119
+ - ``iterator_to_array()``: Pass a ``MongoDB\Driver\Cursor`` object as a parameter
120
+
121
+ The following example calls the ``toArray()`` method on a cursor to store its results
122
+ in an array:
116
123
117
124
.. literalinclude:: /includes/read/cursor.php
118
125
:language: php
@@ -172,6 +179,7 @@ To learn more about cursors, see the following pages in the PHP manual:
172
179
- `MongoDB\\Driver\\Cursor <{+php-manual+}/class.mongodb-driver-cursor.php>`__
173
180
- `MongoDB\\Driver\\Cursor::current() <{+php-manual+}/mongodb-driver-cursor.current.php>`__
174
181
- `MongoDB\\Driver\\Cursor::toArray() <{+php-manual+}/mongodb-driver-cursor.toarray.php>`__
182
+ - `iterator_to_array() <{+php-manual+}/function.iterator-to-array.php>`__
175
183
176
184
API Documentation
177
185
~~~~~~~~~~~~~~~~~
0 commit comments