3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $settings = array( 'simple_value1' => array('nodenodenodenodenodenodenodenode'), 'menu-template-24-prim' => array('menu-template-24-prim' => 24), 'frontpage' => 'node', ); $domains = array( 24 => 26, 55 => 58, 25 => 51, 53 => 29, ); foreach ($domains as $old_id => $cur_id) { $old_menu_prim = 'menu-template-' . $old_id . '-prim'; $old_menu_sec = 'menu-template-' . $old_id . '-sec'; $cur_menu_prim = 'menu-template-' . $cur_id . '-prim'; $cur_menu_sec = 'menu-template-' . $cur_id . '-sec'; // Replace old menu-template-55-prim settings for menu-template-58-prim. foreach ($settings as $menu_name => $setting) { if (!empty($setting[$old_menu_prim])) { $settings[$menu_name][$old_menu_prim] = 0; $settings[$menu_name][$cur_menu_prim] = $cur_menu_prim; } elseif (!empty($setting[$old_menu_sec])) { $settings[$menu_name][$old_menu_sec] = 0; $settings[$menu_name][$cur_menu_sec] = $cur_menu_sec; } } } print_r($settings);
based on sNqI0
Output for 5.0.0 - 5.0.2, 5.4.0 - 7.2.0
Array ( [simple_value1] => Array ( [0] => nodenodenodenodenodenodenodenode ) [menu-template-24-prim] => Array ( [menu-template-24-prim] => 0 [menu-template-26-prim] => menu-template-26-prim ) [frontpage] => node )
Output for 4.3.0 - 4.4.9, 5.0.3 - 5.3.29
Array ( [simple_value1] => Array ( [0] => nodenodenodenodenodenodenodenode ) [menu-template-24-prim] => Array ( [menu-template-24-prim] => 0 [menu-template-26-prim] => menu-template-26-prim ) [frontpage] => mode )