-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayFunctions.php
More file actions
111 lines (86 loc) · 2.16 KB
/
Copy patharrayFunctions.php
File metadata and controls
111 lines (86 loc) · 2.16 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* There are some inbuilt functions for the arrays that we can use on them.
*/
/**
* The first function is - array_combine($keys_arr, $values_array)
*
* It accepts 2 arrays with the same length and gives out an associative array with the first array
* as the keys and the second array as the values
*/
$name = ["Rishi", "Mouli"];
$marks = [30, 40];
$combined = array_combine($name, $marks);
print_r($combined);
echo "<br>";
/**
* The second function is - array_chunk()
*
*/
/**
* The third function is - array_count_values()
*
* It only takes the array, and returns an associative array with the count of
* each unique element in the array
*/
$countMe = ["Block 33", "Block 33", "Block 36", "Block 36", "Block 38", "Block 38"];
print_r(array_count_values($countMe));
/**
* array_diff
*/
/**
* The fifth function is - array_intersect()
*
* It takes n arrays as arguments and the returns the common elements in both of them
*
*
*/
$a1 = array("a" => "red", "b" => "blue");
/**
* The sixth function is - array_merge()
*
* It takes n arrays as arguments and merges them into a single array
*
* if the keys are the same, the value of the last array will be taken
* otherwise, the values will be appended to the array
*/
/**
* The seventh function is - array_push()
*
* It takes an array and a value and appends the value to the end of the array
*/
/**
* The eighth function is - array_pop()
*
* It takes an array and removes the last element from the array
*
*/
/**
* The ninth function is - array_reverse()
*
* It takes an array and returns the reversed array
*/
/**
* The tenth function is - array_slice()
*
* It takes an array, start index, and length as arguments and returns the sliced array
*/
/**
* The eleventh function is - array_column()
*
* It takes an array and the key of the column that we want to extract from the array
*/
$result = array(
array(
'id' => 1,
'first_name' => 'Rishi',
'last_name' => 'Raj',
),
array(
'id' => 3,
'first_name' => 'Mouli',
'last_name' => 'Bhalla',
)
);
echo "<br>";
print_r(array_column($result, 'first_name', 'last_name'));