note 128575 added to function.count
| From: | olja dot fb at gmail dot com | Date: | Sun, 28 May 2023 13:08:13 +0000 |
| Subject: | note 128575 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220531@lists.php.net to get a copy of this message | ||
In example #3, given as:
<?php
$food = array('fruits' => array('orange', 'banana',
'apple'),
'veggie' => array('carrot', 'collard',
'pea'));
// recursive count
var_dump(count($food, COUNT_RECURSIVE));
?>
with the output given as int(8), it may have some readers mistaken, as I was at first: one might
take it as keys being counted as well as the inner array entries:
<?php
// NO:
'fruits', 'orange', 'banana', 'apple',
'veggie', 'carrot', 'collard', 'pea'
?>
But actually keys are not counted in count function, and why it is still 8 - because inner arrays
are counted as entries as well as their inner elements:
<?php
// YES:
array('orange', 'banana', 'apple'), 'orange',
'banana', 'apple',
array('carrot', 'collard', 'pea'), 'carrot',
'collard', 'pea'
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 2a10:8012:9:a124:71b2:4e05:666b:aa9b)
----
Manual Page -- https://php.net/manual/en/function.count.php
Edit -- https://main.php.net/note/edit/128575
Del: integrated -- https://main.php.net/note/delete/128575/integrated
Del: useless -- https://main.php.net/note/delete/128575/useless
Del: bad code -- https://main.php.net/note/delete/128575/bad+code
Del: spam -- https://main.php.net/note/delete/128575/spam
Del: non-english -- https://main.php.net/note/delete/128575/non-english
Del: in docs -- https://main.php.net/note/delete/128575/in+docs
Del: other reasons-- https://main.php.net/note/delete/128575
Reject -- https://main.php.net/note/reject/128575
Search -- https://main.php.net/manage/user-notes.php