I have a large set of results as an array from a cakePHP model for a csv export. I have been formatting using a loop as shown below. As the number of records grow, this is becoming too slow and giving time out errors. Is there a better way to do this using either cakephp hash or php array functions?
foreach($people as $person){
array_push($results, array(
'SchoolName'=> $person['School']['name'],
'SchoolRef' => $person['School']['ref'],
'firstName' => $person['Person']['firstname'],
'LastName' => $person['Person']['lastname'],
'Year1' => $person['Person']['year_1'],
'StudentID' => $person['Person']['studentid'],
'Email' => $person['Person']['email']
));
}
microtime(true)and measure every part of your code. Find the slowest part. Then optimize. In this particular order. If you have some issues optimizing the really slow code - ask another question (or change the current one)array_pushisn't slow by design. I cannot understand why you don't just want to profile your script and start doing real work. 50k you're working with is really tiny, and presumably you have a problem somewhere else. Now it's important to realize that your current assumption is wrong.