2017 © Pedro Peláez
 

library arrayhelper

ArrayHelper based on KohanaPHP::Arr

image

johnykvsky/arrayhelper

ArrayHelper based on KohanaPHP::Arr

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

ArrayHelper

Latest Version on Packagist ![Software License][ico-license] Total Downloads Build Status, (*1)

ArrayHelper - based on KohanaPHP Arr class. Proper merge, without surprises - see usage for example., (*2)

Install

Via Composer, (*3)

``` bash $ composer require johnykvsky/arrayhelper, (*4)


Should work fine on PHP 5.6, but I didn't check that. Just change required PHP version in composer.json and maybe remove dev packages. And type hinting from code. ## Usage ``` php use johnykvsky\Utils\ArrayHelper; $array = array('johny'=>array('age'=>30,'weight'=>70),'chris'=>array('height'=>170)); $array2 = array('hobby'=>array(array('music'=>'rock'))); $result = ArrayHelper::merge($array, $array2); //merge arrays $array3 = array('chris'=>array('weight'=>70)); $array1 = array('fragment' => 'x', 'attributes' => array('title' => 'X', 'class' => array('a', 'b'))); $array2 = array('fragment' => 'y', 'attributes' => array('title' => 'Y', 'class' => array('c', 'd'))); $result = ArrayHelper::merge($array1, $array2); //deep merge, fragment = y / attributes: title = Y / class = a,b,c,d $result = ArrayHelper::merge($array1, $array2, false); //non-deep, fragment = y / attributes title = Y / class = c,d //potential problem with array_merge_recursive: $incorrect = array_merge_recursive($array1, $array2); //result is array('fragment' => array('x', 'y'), 'attributes' => array('title' => array('X', 'Y'), 'class' => array('a', 'b', 'c', 'd'))). $array4 = ['foo' , 'arj','pak']; $array5 = ['foo' => 'tar', 'baz'=>'zip']; //combine - get all values from array5 into array4 $result = ArrayHelper::combine($array4, $array5); //result is ['foo','arj','pak','tar','zip'] $foo = ArrayHelper::firstValue($array5); // tar $baz = ArrayHelper::lastValue($array5); // zip $bar = ArrayHelper::flatten($array1); // ['x','X','a','b']

Testing

``` bash $ composer test, (*5)


## Code checking ``` bash $ composer phpstan $ composer phpstan-max

Security

If you discover any security related issues, please email johnykvsky@protonmail.com instead of using the issue tracker., (*6)

Credits

License

The MIT License (MIT). Please see License File for more information., (*7)

The Versions

23/01 2018

dev-master

9999999-dev https://github.com/johnykvsky/ArrayHelper

ArrayHelper based on KohanaPHP::Arr

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

arrayhelper johnykvsky

27/12 2017

0.0.1

0.0.1.0 https://github.com/johnykvsky/ArrayHelper

ArrayHelper based on KohanaPHP::Arr

  Sources   Download

MIT

The Requires

  • php ~5.6|~7.0

 

The Development Requires

arrayhelper johnykvsky