PHP Classes

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

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 103 All time: 9,767 This week: 206Up
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: 30
All time rank: 2758193 in Brazil Brazil
Week rank: 227 Up20 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 (16)  
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 (16)  /  src  
File Role Description
Files folder imageTransformer (3 files)
  Plain text file ArrayKeys.php Class Class source

  Files folder image Files (16)  /  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 (16)  /  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 (16)  /  test  /  Transformer  
File Role Description
  Plain text file ToCamelCaseTest.php Class Class source
  Plain text file ToSnakeCaseTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:103
This week:0
All time:9,767
This week:206Up