Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2018-05-17 (3 months ago) | | Not yet rated by the users | | Total: 97 | | All time: 9,029 This week: 400 |
|
Description | | Author |
This package can transform an array to change the case of the keys.
It can take an array and perform changes to the entry key strings to switch their case.
Currently it can change the keys string case to camel case, lower case or use a custom change using a closure function. Innovation Award
May 2018
Number 7 |
PHP provides many array manipulation functions for a varied set of purposes, but not for all purposes.
Associative arrays can associate text strings to an associated value but the key text is case sensitive.
This package provides a solution that can recreate an associative array by changing the case of the string of each key.
Manuel Lemos |
| |
|
|
Innovation award
Nominee: 3x |
|
Details
ArrayKeysCaseTransform
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.
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.