note 116726 added to function.count
| From: | array at from dot pl | Date: | Thu, 19 Feb 2015 22:22:45 +0000 |
| Subject: | note 116726 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201761@lists.php.net to get a copy of this message | ||
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
----
Server IP: 72.52.91.14
Probable Submitter: 213.155.167.238
----
Manual Page -- http://php.net/manual/en/function.count.php
Edit -- https://master.php.net/note/edit/116726
Del: integrated -- https://master.php.net/note/delete/116726/integrated
Del: useless -- https://master.php.net/note/delete/116726/useless
Del: bad code -- https://master.php.net/note/delete/116726/bad+code
Del: spam -- https://master.php.net/note/delete/116726/spam
Del: non-english -- https://master.php.net/note/delete/116726/non-english
Del: in docs -- https://master.php.net/note/delete/116726/in+docs
Del: other reasons-- https://master.php.net/note/delete/116726
Reject -- https://master.php.net/note/reject/116726
Search -- https://master.php.net/manage/user-notes.php