function array_camel_case($array, $ucfirst = false) { if (!is_array($array)) { return false; } $return = array(); foreach ($array as $key => $value) { if (strpos($key, '_') !== false) { $newKey = str_replace(' ', '', ucwords(trim(preg_replace('/[^a-z0-9]+/i', ' ', $key)))); if (!$ucfirst) { $newKey = lcfirst($newKey); } } else { $newKey = $key; } if (is_array($value)) { $newValue = array_camel_case($value, $ucfirst); } else { $newValue = $value; } $return[$newKey] = $newValue; } return $return; }
/** * Test function array_camel_case() * * @dataProvider camelCaseProvider */ public function testArrayCamelCase($test, $expected, $uppercase = false) { $this->assertEquals($expected, array_camel_case($test, $uppercase)); }