1 | <?php |
||
18 | class NestedArray |
||
19 | { |
||
20 | /** |
||
21 | * Merges multiple arrays, recursively, and returns the merged array. |
||
22 | * |
||
23 | * This function is similar to PHP's array_merge_recursive() function, but it |
||
24 | * handles non-array values differently. When merging values that are not both |
||
25 | * arrays, the latter value replaces the former rather than merging with it. |
||
26 | * |
||
27 | * Example: |
||
28 | * @code |
||
29 | * $link_options_1 = array('fragment' => 'x', 'attributes' => array('title' => t('X'), 'class' => array('a', 'b'))); |
||
30 | * $link_options_2 = array('fragment' => 'y', 'attributes' => array('title' => t('Y'), 'class' => array('c', 'd'))); |
||
31 | * |
||
32 | * // This results in array( |
||
33 | * // 'fragment' => array('x', 'y'), |
||
34 | * // 'attributes' => array('title' => array(t('X'), t('Y')), 'class' => array('a', 'b', 'c', 'd')) |
||
35 | * // ). |
||
36 | * $incorrect = array_merge_recursive($link_options_1, $link_options_2); |
||
37 | * |
||
38 | * // This results in array( |
||
39 | * // 'fragment' => 'y', |
||
40 | * // 'attributes' => array('title' => t('Y'), 'class' => array('a', 'b', 'c', 'd')) |
||
41 | * // ). |
||
42 | * $correct = NestedArray::mergeDeep($link_options_1, $link_options_2); |
||
43 | * @endcode |
||
44 | * |
||
45 | * Note: This function was derived from Drupal's drupal_array_merge_deep(). |
||
46 | * |
||
47 | * @param array ... |
||
48 | * Arrays to merge. |
||
49 | * |
||
50 | * @return array |
||
51 | * The merged array. |
||
52 | */ |
||
53 | public static function mergeDeep() |
||
77 | } |
||
78 |