In following PHP script iterator_to_array
is extremely inefficient (I used a profiler). Is there any better alternative for following code?
$new = [];
$rows=(new Mongo())->table1->find(['foo' => 'bar'),
$new['string'] = iterator_to_array($rows); //Time-consuming part
(new Mongo())->table2->save($new);
I think there is no alternative, if you have an iterator and you want an array, you need to iterate the iterator and pass the values to the array, you can do it by yourself using foreach
or you can use iterator_to_array
, but if you have many elements in the iterator, the process is time-consuming.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With