note 114924 modified in function.count by cmb

From: Date: Tue, 04 Oct 2016 17:53:43 +0000
Subject: note 114924 modified in function.count by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-206758@lists.php.net to get a copy of this message
[Editor's note: array at from dot pl had pointed out that count() is a cheap operation; however, there's still the function call overhead.] If you want to run through large arrays don't use count() function in the loops , its a over head in performance, copy the count() value into a variable and use that value in loops for a better performance. Eg: // Bad approach for($i=0;$i<count($some_arr);$i++) { // calculations } // Good approach $arr_length = count($some_arr); for($i=0;$i<$arr_length;$i++) { // calculations } --was-- If you want to run through large arrays don't use count() function in the loops , its a over head in performance, copy the count() value into a variable and use that value in loops for a better performance. Eg: // Bad approach for($i=0;$i<count($some_arr);$i++) { // calculations } // Good approach $arr_length = count($some_arr); for($i=0;$i<$arr_length;$i++) { // calculations } http://php.net/manual/en/function.count.php

« previous php.notes (#206758) next »