3 ms·
Well, imagine that the query returns 1000 (or a million or what not) results. You've looped through it once already in the getSnsWithoutIds() to build the $sns
by leftnode 17y ago
Well, imagine that the query returns 1000 (or a million or what not) results. You've looped through it once already in the getSnsWithoutIds() to build the $sns array (which you should use $sns[] = $row['aim_sn'], its faster). So, you've looped through everything, which takes some time, and now you have a huge data structure in memory that you may not need.
Then, you loop through it again with the foreach. What if you wanted to paginate those results quickly? What if you only wanted a subset of the whole pie?
This class, as I'll show in a future article, can easily be extended to allow for easy pagination and filtering of your data.
- zackattack 17y agoWell, it takes a trivial amount of time to loop through an array with a million results. So can you please clarify the benefit of the class as-is, besides its purported future extensiblity? I don't get the time to unset() the array before I return it, but you do? BTW I did a test, and it seems that $array[] is a faster way to append.
- jrockway 17y agoBTW I did a test, and it seems that $array[] is a faster way to append. Classic PHP-style micro-optimization. If you can't use the right algorithm, you can at least make the wrong one run 0.34% faster.