PHP Classes
elePHPant
Icontem

PHP Array Keys Case Transform: Transform an array to change the case of the keys

Recommend this page to a friend!
  Info   View files Documentation   View files View files (16)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-05-17 (3 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 97 All time: 9,029 This week: 400Up
Version License PHP version Categories
array-keys-case-tran 1.0.0GNU General Publi...5PHP 5, Text processing, Data types
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
PHP Programming Innovation award nominee
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
  Performance   Level  
Name: Lucas de Oliveira <contact>
Classes: 3 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 3x

Details

ArrayKeysCaseTransform

Build Status Code Coverage Code Quality License MIT Packagist

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.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file, 1 directory)
Files folder imagetest (2 files, 1 directory)
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.xml Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageTransformer (3 files)
  Plain text file ArrayKeys.php Class Class source

  Files folder image Files  /  src  /  Transformer  
File Role Description
  Plain text file AbstractTransformer.php Class Class source
  Plain text file ToCamelCase.php Class Class source
  Plain text file ToSnakeCase.php Class Class source

  Files folder image Files  /  test  
File Role Description
Files folder imageTransformer (2 files)
  Plain text file ArrayKeysTest.php Class Class source
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script

  Files folder image Files  /  test  /  Transformer  
File Role Description
  Plain text file ToCamelCaseTest.php Class Class source
  Plain text file ToSnakeCaseTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:97
This week:0
All time:9,029
This week:400Up