-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcount.php
More file actions
39 lines (31 loc) · 798 Bytes
/
Copy pathcount.php
File metadata and controls
39 lines (31 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
$arr = array(0,
false,
"string",
null,
array("res1","res2",array("resres1")),
);
// print_r($arr); not good to print with an array have false, null value
print_r($arr);
print_r(array_count_values($arr));
echo count($arr);
echo count($arr, COUNT_RECURSIVE);
//count empty array
$arr = array();
echo count($arr);
//count in limit depth
function count_recursive($array, $limit)
{
$count = 0;
foreach ($array as $id => $_array) {
if (is_array($_array) && $limit > 0) {
$count += count_recursive($_array, $limit - 1);
} else {
$count += 1;
}
}
return $count;
}
echo"1: ".count_recursive($arr, 0);
echo"2: ".count_recursive($arr, 1);
echo"3: ".count_recursive($arr, 2);