1 | <?php |
||
10 | abstract class ArrayUtilities |
||
11 | { |
||
12 | /** |
||
13 | * @param array $array |
||
14 | * |
||
15 | * @return bool |
||
16 | */ |
||
17 | 9 | public static function is_multidimensional(array &$array) |
|
29 | |||
30 | /** |
||
31 | * Check whether the elements of a multidimensional array can be indexed based on a key. |
||
32 | * |
||
33 | * In the following example, the array can be indexed with the 'name' key. |
||
34 | * |
||
35 | * ```php |
||
36 | * array( |
||
37 | * array('name' => 'sample 1'), |
||
38 | * array('name' => 'sample 2'), |
||
39 | * array('name' => 'sample 3'), |
||
40 | * ) |
||
41 | * ``` |
||
42 | * |
||
43 | * @param array $arr |
||
44 | * @param string $indexKey The key to consider the index |
||
45 | * |
||
46 | * @return bool |
||
47 | */ |
||
48 | 44 | public static function array_can_be_indexed(array &$arr, $indexKey) |
|
60 | |||
61 | /** |
||
62 | * Index an array passed on given key. |
||
63 | * |
||
64 | * The resulting array would be as follows when indexed by the 'name' key. |
||
65 | * |
||
66 | * ```php |
||
67 | * array( |
||
68 | * 'sample 1' => array('name' => 'sample 1'), |
||
69 | * 'sample 2' => array('name' => 'sample 2'), |
||
70 | * 'sample 3' => array('name' => 'sample 3'), |
||
71 | * ) |
||
72 | * ``` |
||
73 | * |
||
74 | * @param array $arr |
||
75 | * @param string $indexKey |
||
76 | * |
||
77 | * @see ArrayUtilities::array_can_be_indexed() |
||
78 | * |
||
79 | * @return array The original array but each element's key will be the value of the element's key value |
||
80 | */ |
||
81 | 4 | public static function array_index_by_key(array &$arr, $indexKey) |
|
95 | |||
96 | /** |
||
97 | * Merge two arrays together while respecting possible indexing. |
||
98 | * |
||
99 | * @param array $arr1 The first array |
||
100 | * @param array $arr2 The values in this array will overwrite the respective values from $arr2 |
||
101 | * @param string $indexKey The key to respect when indexing |
||
102 | * |
||
103 | * @see ArrayUtilities::array_index_by_key() |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | 53 | public static function array_merge_defaults(array &$arr1, array &$arr2, $indexKey) |
|
134 | |||
135 | /** |
||
136 | * Split an associative array into two chunks based on the position of a key. |
||
137 | * |
||
138 | * @param string $key The key we'll be using as the splitting point |
||
139 | * @param array $array The array we're splitting up |
||
140 | * @param bool $inclusive When set to true, the key being used as the splitting point will be incorporated in the |
||
141 | * first chunk of the split. |
||
142 | * |
||
143 | * @return array An array with two indices (0 & 1) containing the respective chunks of the array |
||
144 | */ |
||
145 | 9 | public static function associative_array_split($key, array &$array, $inclusive = true) |
|
155 | } |
||
156 |
This check looks for method names that are not written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes
databaseConnectionSeeker
.