I have a PHP / MySQL script which gets data from my database.
I created a PHP function to sort it all (the result is an array of objects), like this:
$allData = $Data->showAll($start->format('Y'), $start->format('m'));
//To sort the results by alphabetical order
function orderByName($a, $b) {
return strcasecmp($a->nom, $b->nom);
}
if ($allData):{
usort($allData, "orderByName");
//script
}
When I have a lot of data, the function is slowing down the page, which is not surprising. But what’s really interesting is that the page is slowed down even when the function is only defined, but not called!
Like this:
$allData = $Data->showAll($start->format('Y'), $start->format('m'));
//To sort the results by alphabetical order
function orderByName($a, $b) {
return strcasecmp($a->nom, $b->nom);
}
if ($allData):{
//usort($allData, "orderByName");
//script
}
To go back to the initial loading speed of the page, I need to comment also the definition of the function…
Why is it like this?
And anyone has a suggestion for sorting alphabetically a big array of objects?