I am trying to convert the keys of a multi-dimensional array from CamelCase to snake_case, with the added complication that some keys have an exclamation mark that I\'d like rem
Create a function like:
function convertToCamelCase($array){
$finalArray = array();
foreach ($array as $key=>$value):
if(strpos($key, "_"))
$key = lcfirst(str_replace("_", "", ucwords($key, "_"))); //let's convert key into camelCase
if(!is_array($value))
$finalArray[$key] = $value;
else
$finalArray[$key] = $this->_convertToCamelCase($value );
endforeach;
return $finalArray;
}
and call this like:
$newArray = convertToCamelCase($array);
for working example see this