I've encountered the following problem:
private function getMyThemeIds($collection){
$result = [];
...
foreach ($results as $doc) {
file_put_contents('2.txt', $doc->getUnid()); //everything is fine here
$result[] = $doc->getUnid();
file_put_contents('3.txt', print_r($result,true)); //again, array is just fine, barely 4000 entries
}
file_put_contents('4.txt', print_r($result,true)); // but here we see what was in this array right after initialization. Nothing in this case.
return $result;
}
I've tried different approaches - changed foreach
to for
, $result[]
to array_push
, etc with no avail. Anybody knows what the cause of this may be?
php
version? If you are belowphp-5.4
than change$result = [];
to$result = array();
– Chayan Oct 21 at 6:24$doc->getUnid();
prints proper output? It must not return empty. – sandeepsure Oct 21 at 6:27