- var_export: documentation ( source)
- strtoupper: documentation ( source)
<?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));