326 | | if ( ! function_exists( 'array_replace_recursive' ) ) : |
327 | | /** |
328 | | * PHP-agnostic version of {@link array_replace_recursive()}. |
329 | | * |
330 | | * The array_replace_recursive() function is a PHP 5.3 function. WordPress |
331 | | * currently supports down to PHP 5.2, so this method is a workaround |
332 | | * for PHP 5.2. |
333 | | * |
334 | | * Note: array_replace_recursive() supports infinite arguments, but for our use- |
335 | | * case, we only need to support two arguments. |
336 | | * |
337 | | * Subject to removal once WordPress makes PHP 5.3.0 the minimum requirement. |
338 | | * |
339 | | * @since 4.5.3 |
340 | | * |
341 | | * @see https://secure.php.net/manual/en/function.array-replace-recursive.php#109390 |
342 | | * |
343 | | * @param array $base Array with keys needing to be replaced. |
344 | | * @param array $replacements Array with the replaced keys. |
345 | | * |
346 | | * @return array |
347 | | */ |
348 | | function array_replace_recursive( $base = array(), $replacements = array() ) { |
349 | | foreach ( array_slice( func_get_args(), 1 ) as $replacements ) { |
350 | | $bref_stack = array( &$base ); |
351 | | $head_stack = array( $replacements ); |
352 | | |
353 | | do { |
354 | | end( $bref_stack ); |
355 | | |
356 | | $bref = &$bref_stack[ key( $bref_stack ) ]; |
357 | | $head = array_pop( $head_stack ); |
358 | | |
359 | | unset( $bref_stack[ key( $bref_stack ) ] ); |
360 | | |
361 | | foreach ( array_keys( $head ) as $key ) { |
362 | | if ( isset( $key, $bref ) && |
363 | | isset( $bref[ $key ] ) && is_array( $bref[ $key ] ) && |
364 | | isset( $head[ $key ] ) && is_array( $head[ $key ] ) ) { |
365 | | |
366 | | $bref_stack[] = &$bref[ $key ]; |
367 | | $head_stack[] = $head[ $key ]; |
368 | | } else { |
369 | | $bref[ $key ] = $head[ $key ]; |
370 | | } |
371 | | } |
372 | | } while ( count( $head_stack ) ); |
373 | | } |
374 | | |
375 | | return $base; |
376 | | } |
377 | | endif; |
378 | | |