khuddus / php-camel-case-helpers
A php tool to convert underscored or dashed arrays to camelcased arrays
1.0.0
2019-12-22 13:49 UTC
Requires
- php: >=7.2.0
Requires (Dev)
- phpunit/phpunit: >=8.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2026-05-01 02:35:57 UTC
README
A PHP library that provides camel case helpers. Convert array keys or strings containing underscores, hyphens, or spaces into camelCase.
Requirements
- PHP >= 8.1
Install
composer require khuddus/php-camel-case-helpers
Usage
String Helper
Converts 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"); // helloBeautifulWorld
Array Helper
Recursively 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', ], ], ], ], ] */
Testing
composer test
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email khuddus1+github@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.