PHP Classes

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    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 103 This week: 1All time: 9,739 This week: 560Up
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
Picture of Lucas de Oliveira
  Performance   Level  
Name: Lucas de Oliveira <contact>
Classes: 5 packages by
Country: Brazil Brazil
Age: 29
All time rank: 2755192 in Brazil Brazil
Week rank: 416 Up36 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 5x

Documentation

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:103
This week:1
All time:9,739
This week:560Up