note 112989 deleted from function.count by cmb

From: Date: Tue, 04 Oct 2016 18:05:35 +0000
Subject: note 112989 deleted from function.count by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-206766@lists.php.net to get a copy of this message
Note Submitter: semmelbroesel at gmail dot com ---- I've read this somewhere else before, but experienced it first hand now, so I thought I'd post it here. While in regular use, count() is pretty fast, this changes rapidly when used in a for loop. Example: for ($x = 0; $x < count($array); $x++) { // some code here } If your array contains a lot of data, this code gets slowed down significantly. Better way to write this: $arrayCount = count($array); for ($x = 0; $x < $arrayCount; $x++) { // some code here } I didn't think it would make such a difference, but it did in my case - changed 15 seconds load time into 1 second!

« previous php.notes (#206766) next »