2017 © Pedro Peláez
 

library array-key-glue

Implode keys of array recursively

image

jongpak/array-key-glue

Implode keys of array recursively

  • Sunday, September 11, 2016
  • by jongpak
  • Repository
  • 1 Watchers
  • 1 Stars
  • 235 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

jongpak/array-key-glue

Implode keys of array recursively, (*1)

Build Status Scrutinizer Code Quality codecov, (*2)

Simple usage

use Prob\ArrayUtil\KeyGlue;

$array = [
    'A' => [
        'B' => 'Value1',
        'C' => 'Value2',
        'D' => [
            'E' => 'Value3',
            'F' => 'Value4'
        ]
    ],
    'G' => [
        'H',
        'I',
        'J'
    ]
];

$glue = new KeyGlue();
$glue->setArray($array);
$glue->setGlueCharacter('.');   // glue '.'
$glue->glueOnlyKey();
/*
 * Array
 * (
 *     [0] => A.B
 *     [1] => A.C
 *     [2] => A.D.E
 *     [3] => A.D.F
 *     [4] => G
 * )
 */
$glue->setGlueCharacter('.');   // glue '.'
$glue->glueKeyAndContainValue();
/*
 * Array
 * (
 *     [A.B]    => 'Value1'
 *     [A.C]    => 'Value2'
 *     [A.D.E]  => 'Value3'
 *     [A.D.F]  => 'Value4'
 *     [G]      => ['H', 'I', 'J']
 * )
 */
$glue->setGlueCharacter(' -> ');    // glue ' -> '
$glue->glueOnlyKey();
/*
 * Array
 * (
 *     [0] => A -> B
 *     [1] => A -> C
 *     [2] => A -> D -> E
 *     [3] => A -> D -> F
 *     [4] => G
 * )
 */
$glue->setGlueCharacter(' -> ');    // glue ' -> '
$glue->glueKeyAndContainValue();
/*
 * Array
 * (
 *     [A -> B]         => 'Value1'
 *     [A -> C]         => 'Value2'
 *     [A -> D -> E]    => 'Value3'
 *     [A -> D -> F]    => 'Value4'
 *     [G]              => ['H', 'I', 'J']
 * )
 */

The Versions

11/09 2016

dev-master

9999999-dev https://github.com/jongpak/array-key-glue

Implode keys of array recursively

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires