deoliveiralucas / array-keys-case-transform
Simple library to handle words case transformation from array keys
1.1.1
2020-08-04 13:58 UTC
Requires
- php: >=7.1.0
- icanboogie/inflector: ^1.4 || ^2.0
Requires (Dev)
- phpunit/phpunit: ^7
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: *
- zendframework/zend-coding-standard: ^1.0
This package is auto-updated.
Last update: 2024-11-04 23:14:18 UTC
README
Simple library to handle words case transformation from array keys.
Installation
composer require deoliveiralucas/array-keys-case-transform
Usage
use ArrayKeysCaseTransform\ArrayKeys; $input = [ 'first_key' => 'value' ]; print_r(ArrayKeys::toCamelCase($input)); /* Output: Array ( [firstKey] => value ) */ $input = [ 'firstKey' => 'value' ]; print_r(ArrayKeys::toSnakeCase($input)); /* Output: Array ( [first_key] => value ) */
Custom format
use ArrayKeysCaseTransform\ArrayKeys; use ArrayKeysCaseTransform\Transformer\AbstractTransformer; $input = [ 'firstKey' => 'value' ]; $customTransform = new class extends AbstractTransformer { protected function format(string $key) : string { return str_replace('Key', 'CustomKey', $key); } }; print_r(ArrayKeys::transform($customTransform, $input)); /* Output: Array ( [firstCustomKey] => value ) */
Contributing
Please see CONTRIBUTING for details.
License
ArrayKeysCaseTransform is released under the MIT License. Please see License File for more information.