WordPress array_replace_recursive() Function Kodu
WordPress array_replace_recursive() Function Kodu
Array_replace_recursive () işlevi, bir PHP 5.3 fonksiyonudur. WordPress şu anda PHP 5.2’ye kadar desteklemektedir, bu nedenle bu yöntem PHP 5.2 için bir geçici çözümdür.
Not: array_replace_recursive () sonsuz argümanları destekler, ancak kullanım durumumuz için sadece iki argümanı desteklememiz gerekir.
Bir kez kaldırılmaya tabi WordPress, PHP 5.3.0’ı minimum gereksinim yapar.
function array_replace_recursive( $base = array(), $replacements = array() ) {
foreach ( array_slice( func_get_args(), 1 ) as $replacements ) {
$bref_stack = array( &$base );
$head_stack = array( $replacements );
do {
end( $bref_stack );
$bref = &$bref_stack[ key( $bref_stack ) ];
$head = array_pop( $head_stack );
unset( $bref_stack[ key( $bref_stack ) ] );
foreach ( array_keys( $head ) as $key ) {
if ( isset( $key, $bref ) &&
isset( $bref[ $key ] ) && is_array( $bref[ $key ] ) &&
isset( $head[ $key ] ) && is_array( $head[ $key ] ) ) {
$bref_stack[] = &$bref[ $key ];
$head_stack[] = $head[ $key ];
} else {
$bref[ $key ] = $head[ $key ];
}
}
} while ( count( $head_stack ) );
}
return $base;
}