note 116726 deleted from function.count by cmb

From: Date: Tue, 04 Oct 2016 17:53:53 +0000
Subject: note 116726 deleted from function.count by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-206759@lists.php.net to get a copy of this message
Note Submitter: array at from dot pl ---- onlyranga at gmail dot com note about keeping count() in variable is not really correct, For some time now using variable and calling count() on each loop iteration costs you basically the same. Proof: If you look into PHP sources then you see that for some time now it returns internal counter value instead of counting on each call. Here is count implementation: [1] where for array it calls php_count_recursive [2] which is then calls zend_hash_num_elements and returns nNumOfElements internal variable. It is not counting anything. You may want to read this blog post about PHP internals too: https://nikic.github.io/2012/03/28/Understanding-PHPs-internal-array-implementation.html [1] https://github.com/php/php-src/blob/PHP-5.5/ext/standard/array.c#L306 [2] https://github.com/php/php-src/blob/e10e151e9b92313a7085272c85bebf6c82017fce/ext/standard/array.c#L264

« previous php.notes (#206759) next »