A PHP library that provides camel case helpers. Convert array keys or strings containing underscores, hyphens, or spaces into camelCase.
- PHP >= 8.1
composer require khuddus/php-camel-case-helpersConverts a string to camelCase.
use Khuddus\Helpers\CamelCase\StringHelper;
StringHelper::convertToCamelCasedString("Hello world"); // helloWorld
StringHelper::convertToCamelCasedString("Hello-world"); // helloWorld
StringHelper::convertToCamelCasedString("Hello_world"); // helloWorld
StringHelper::convertToCamelCasedString("hello_beautiful_world"); // helloBeautifulWorldRecursively converts all non-numeric array keys to camelCase.
use Khuddus\Helpers\CamelCase\ArrayHelper;
// Convert all levels (default)
ArrayHelper::convertToCamelCasedArray(['hello_world' => 1]);
// ['helloWorld' => 1]
// Limit conversion depth with the optional $level parameter
// $level = 0 → no conversion
// $level = 1 → top-level keys only
// $level = null (default) → all levels
ArrayHelper::convertToCamelCasedArray([
'Hello World' => [
'My----World' => 'this world',
],
[
'another -_-_WOrld' => [
'Busy_World' => [
'instruMental World' => [
'courageous--World' => 'mine',
],
],
],
],
], 3);
/*
[
'helloWorld' => [
'myWorld' => 'this world',
],
[
'anotherWOrld' => [
'busyWorld' => [
'instruMental World' => [ // level 3 — not converted
'courageous--World' => 'mine',
],
],
],
],
]
*/composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email khuddus1+github@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.