3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $testArray = ['a' => ['b' => 'l'], 'c' => 'm', 'd' => ['n' => 'o']]; $actionArray = ['setType' => ['b' => 'int']]; function toUpperRecursive($arr, $actionArray) { foreach ($arr as $key => $val) { if (is_array($val)) { // $newKey = strtoupper($key); $arr[$key] = toUpperRecursive($val, $actionArray); // unset($arr[$key]); } elseif (is_string($val)) { echo $key . "\n"; echo $val . "\n"; foreach($actionArray as $actionType => $keyParamArray) { echo $actionType . "\n"; // echo $foo . "\n"; foreach ($keyParamArray as $actionKey => $actionParam) { if($key === $actionKey) { switch ($actionType) { case 'setType': echo $actionParam . "\n"; $arr[$key] = $val . ' + 1111'; break; } } } } } } return $arr; } // echo "before:\n"; // var_export($testArray); // echo "after:\n"; // var_export(toUpperRecursive($testArray)); var_export(toUpperRecursive($testArray, $actionArray));
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.1.0 - 7.3.0rc2
b l setType int c m setType n o setType array ( 'a' => array ( 'b' => 'l + 1111', ), 'c' => 'm', 'd' => array ( 'n' => 'o', ), )