3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $testArray = ['a' => ['b' => 'l'], 'c' => 'm', 'd' => ['n' => 'o']]; $actionArray = ['b' => 'action']; function toUpperRecursive($arr, $actionArray) { foreach ($arr as $key => $val) { if (is_array($val)) { $newKey = strtoupper($key); $arr[$newKey] = toUpperRecursive($val, $actionArray); unset($arr[$key]); } elseif (is_string($val)) { foreach($actionArray as $actionKey => $action) { if($key === $actionKey) { $arr[$key] = $val . ' + 1111'; } } } } return $arr; } // echo "before:\n"; // var_export($testArray); // echo "after:\n"; // var_export(toUpperRecursive($testArray)); var_export(toUpperRecursive($testArray, $actionArray));
based on gSEHA
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.1.0 - 7.2.11
array ( 'c' => 'm', 'A' => array ( 'b' => 'l + 1111', ), 'D' => array ( 'n' => 'o', ), )