Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iterator_to_array is too slow

Tags:

php

mongodb

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);
like image 417
Handsome Nerd Avatar asked Nov 03 '22 19:11

Handsome Nerd


1 Answers

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.

like image 148
m4t1t0 Avatar answered Nov 15 '22 05:11

m4t1t0