1 | <?php |
||
18 | class NestedArray |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * Merges multiple arrays, recursively, and returns the merged array. |
||
23 | * |
||
24 | * This function is similar to PHP's array_merge_recursive() function, but |
||
25 | * it handles non-array values differently. When merging values that are |
||
26 | * not both arrays, the latter value replaces the former rather than |
||
27 | * merging with it. |
||
28 | * |
||
29 | * Example: |
||
30 | * |
||
31 | * @code |
||
32 | * $link_options_1 = array('fragment' => 'x', 'attributes' => array('title' => t('X'), 'class' => array('a', 'b'))); |
||
33 | * $link_options_2 = array('fragment' => 'y', 'attributes' => array('title' => t('Y'), 'class' => array('c', 'd'))); |
||
34 | * |
||
35 | * // This results in array('fragment' => array('x', 'y'), 'attributes' => |
||
36 | * // array('title' => array(t('X'), t('Y')), 'class' => array('a', 'b', |
||
37 | * // 'c', 'd'))). |
||
38 | * $incorrect = array_merge_recursive($link_options_1, $link_options_2); |
||
39 | * |
||
40 | * // This results in array('fragment' => 'y', 'attributes' => |
||
41 | * // array('title' => t('Y'), 'class' => array('a', 'b', 'c', 'd'))). |
||
42 | * $correct = NestedArray::mergeDeep($link_options_1, $link_options_2); |
||
43 | * @endcode |
||
44 | * |
||
45 | * @param array ... |
||
46 | * Arrays to merge. |
||
47 | * |
||
48 | * @return array |
||
49 | * The merged array. |
||
50 | * |
||
51 | * @see NestedArray::mergeDeepArray() |
||
52 | */ |
||
53 | 5 | public static function mergeDeep() |
|
57 | |||
58 | /** |
||
59 | * Merges multiple arrays, recursively, and returns the merged array. |
||
60 | * |
||
61 | * This function is equivalent to NestedArray::mergeDeep(), except the |
||
62 | * input arrays are passed as a single array parameter rather than |
||
63 | * a variable parameter list. |
||
64 | * |
||
65 | * The following are equivalent: |
||
66 | * - NestedArray::mergeDeep($a, $b); |
||
67 | * - NestedArray::mergeDeepArray(array($a, $b)); |
||
68 | * |
||
69 | * The following are also equivalent: |
||
70 | * - call_user_func_array('NestedArray::mergeDeep', $arrays_to_merge); |
||
71 | * - NestedArray::mergeDeepArray($arrays_to_merge); |
||
72 | * |
||
73 | * @param array $arrays |
||
74 | * An arrays of arrays to merge. |
||
75 | * @param bool $preserve_integer_keys |
||
76 | * (optional) If given, integer keys will be preserved and merged |
||
77 | * instead of appended. Defaults to false. |
||
78 | * |
||
79 | * @return array |
||
80 | * The merged array. |
||
81 | * |
||
82 | * @see NestedArray::mergeDeep() |
||
83 | */ |
||
84 | 20 | public static function mergeDeepArray( |
|
112 | } |
||
113 | // vim:sw=4:ts=4:sts=4:et: |
||
114 |
This check marks parameter names that have not been 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 string becomes
databaseConnectionString
.