-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCount_function.php
56 lines (32 loc) · 1.21 KB
/
Count_function.php
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!-- //The sizeof() function returns the number of elements in an array.
// Syntax: sizeof(array, mode)
// The sizeof() function is an alias of the count() function.
//The count() function returns the number of elements in an array.
//Syntax: count(array, mode)
/*
array: Required. Specifies the array
mode: Optional. Specifies the mode.
Possible values:
0 - Default. Does not count all elements of multidimensional arrays
1 - Counts the array recursively (counts all the elements of multidimensional arrays) */ -->
<?php
$food = array('orange','banana','apple','apple');
echo count($food) . "<br>";//4
echo sizeof($food) . "<br>";//4
$len = count($food);
for($i =0; $i < $len; $i++) {
echo $food[$i] . "<br>";
}
// echo array_count_values($food);//return array
print_r(array_count_values($food));
echo "<br>";
//Creating array 1st type is fruits and 2nd type is veggie.
$name = [
'fruits' => ['orange','banana','apple'],
'veggie' => array('carrot','brinjal','pea')
];
// 1st array is fruits and 2nd array is veggie and both have three values
echo count($name) . "<br>";//2
echo count($name,1) . "<br>";//8 i.e fruits has 4 and veggie has 4
echo sizeof($name['fruits'],1);//3
?>