EDD_SL_Plugin_Updater.php
9 years ago
ad-ajax.php
9 years ago
ad-debug.php
9 years ago
ad-model.php
9 years ago
ad-select.php
9 years ago
ad.php
9 years ago
ad_ajax_callbacks.php
9 years ago
ad_group.php
9 years ago
ad_placements.php
9 years ago
ad_type_abstract.php
11 years ago
ad_type_content.php
9 years ago
ad_type_group.php
10 years ago
ad_type_image.php
9 years ago
ad_type_plain.php
9 years ago
checks.php
9 years ago
display-conditions.php
9 years ago
filesystem.php
9 years ago
frontend_checks.php
9 years ago
plugin.php
9 years ago
upgrades.php
9 years ago
utils.php
9 years ago
visitor-conditions.php
9 years ago
widget.php
9 years ago
utils.php
45 lines
| 1 | <?php |
| 2 | class Advanced_Ads_Utils { |
| 3 | /** |
| 4 | * Merges multiple arrays, recursively, and returns the merged array. |
| 5 | * |
| 6 | * This function is similar to PHP's array_merge_recursive() function, but it |
| 7 | * handles non-array values differently. When merging values that are not both |
| 8 | * arrays, the latter value replaces the former rather than merging with it. |
| 9 | * |
| 10 | * Example: |
| 11 | * $link_options_1 = array( 'fragment' => 'x', 'class' => array( 'a', 'b' ) ); |
| 12 | * $link_options_2 = array( 'fragment' => 'y', 'class' => array( 'c', 'd' ) ); |
| 13 | * // This results in array( 'fragment' => 'y', 'class' => array( 'a', 'b', 'c', 'd' ) ). |
| 14 | * |
| 15 | * @param array $arrays An arrays of arrays to merge. |
| 16 | * @param bool $preserve_integer_keys (optional) If given, integer keys will be preserved and merged instead of appended. |
| 17 | * @return array The merged array. |
| 18 | * @copyright Copyright 2001 - 2013 Drupal contributors. License: GPL-2.0+. Drupal is a registered trademark of Dries Buytaert. |
| 19 | */ |
| 20 | public static function merge_deep_array( array $arrays, $preserve_integer_keys = FALSE ) { |
| 21 | $result = array(); |
| 22 | foreach ( $arrays as $array ) { |
| 23 | if ( ! is_array( $array ) ) { continue; } |
| 24 | |
| 25 | foreach ( $array as $key => $value ) { |
| 26 | // Renumber integer keys as array_merge_recursive() does unless |
| 27 | // $preserve_integer_keys is set to TRUE. Note that PHP automatically |
| 28 | // converts array keys that are integer strings (e.g., '1') to integers. |
| 29 | if ( is_integer( $key ) && ! $preserve_integer_keys ) { |
| 30 | $result[] = $value; |
| 31 | } |
| 32 | // Recurse when both values are arrays. |
| 33 | elseif ( isset( $result[ $key ] ) && is_array( $result[ $key ] ) && is_array( $value ) ) { |
| 34 | $result[ $key ] = self::merge_deep_array( array( $result[ $key ], $value ), $preserve_integer_keys ); |
| 35 | } |
| 36 | // Otherwise, use the latter value, overriding any previous value. |
| 37 | else { |
| 38 | $result[ $key ] = $value; |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | return $result; |
| 43 | } |
| 44 | } |
| 45 | ?> |