khuddus/php-camel-case-helpers

A php tool to convert underscored or dashed arrays to camelcased arrays

Maintainers

Package info

github.com/khuddus/php-camel-case-helpers

pkg:composer/khuddus/php-camel-case-helpers

Statistics

Installs: 85

Dependents: 0

Suggesters: 0

Stars: 4

Open Issues: 0

1.0.0 2019-12-22 13:49 UTC

This package is auto-updated.

Last update: 2026-05-01 02:35:57 UTC


README

Latest Version on Packagist Software License Build Status Total Downloads

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.