note 118512 added to function.count
| From: | ThisIsNotImportant | Date: | Thu, 17 Dec 2015 15:10:51 +0000 |
| Subject: | note 118512 added to function.count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204473@lists.php.net to get a copy of this message | ||
About 2d arrays, you have many way to count elements :
<?php
$MyArray = array ( array(1,2,3),
1,
'a',
array('a','b','c','d') );
// All elements
echo count($MyArray ,COUNT_RECURSIVE); // output 11 (9 values + 2 arrays)
// First level elements
echo count($MyArray ); // output 4 (2 values+ 2 arrays)
// Both level values, but only values
echo(array_sum(array_map('count',$MyArray ))); //output 9 (9 values)
// Only second level values
echo (count($MyArray ,COUNT_RECURSIVE)-count($MyArray )); //output 7 ((all elements) - (first
elements))
?>
----
Server IP: 83.137.20.135
Probable Submitter: 185.9.152.22
----
Manual Page -- http://php.net/manual/en/function.count.php
Edit -- https://master.php.net/note/edit/118512
Del: integrated -- https://master.php.net/note/delete/118512/integrated
Del: useless -- https://master.php.net/note/delete/118512/useless
Del: bad code -- https://master.php.net/note/delete/118512/bad+code
Del: spam -- https://master.php.net/note/delete/118512/spam
Del: non-english -- https://master.php.net/note/delete/118512/non-english
Del: in docs -- https://master.php.net/note/delete/118512/in+docs
Del: other reasons-- https://master.php.net/note/delete/118512
Reject -- https://master.php.net/note/reject/118512
Search -- https://master.php.net/manage/user-notes.php