2017 © Pedro Peláez
 

library php-array

PHP Array Utilities

image

hugsbrugs/php-array

PHP Array Utilities

  • Friday, March 17, 2017
  • by hugsbrugs
  • Repository
  • 1 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

php-array

This librairy provides utilities function to ease array manipulation, (*1)

Build Status Coverage Status, (*2)

Install

Install package with composer, (*3)

composer require hugsbrugs/php-array

In your PHP code, load library, (*4)

require_once __DIR__ . '/../vendor/autoload.php';
use Hug\HArray\HArray as HArray;

Note: I couldn't use Array as namespace because it's a PHP reserved word so it's why namespace is HArray ..., (*5)

Usage

Shuffle an array while preserving keys, (*6)

HArray::shuffle_assoc(&$array);

Sort an array based on column filter and optional sort direction, (*7)

HArray::array_sort_by_column(&$arr, $col, $dir = SORT_ASC);

Sort a 2 dimensional array based on 1 or more indexes., (*8)

$new_array = HArray::msort($array, $key, $sort_flags = SORT_REGULAR);

Recursively implodes an array with optional key inclusion, (*9)

$string = HArray::recursive_implode($glue, array $array, $include_keys = false, $trim_all = true);

Transforms an object (and object of object) into an array, (*10)

$new_array = HArray::object_to_array($obj);

Count in 2 dimensions arrays, number of rows in sub arrays, (*11)

$count = HArray::sub_count($array);

Cuts a string into an array of strings depending of word count, (*12)

$new_array = HArray::string_to_array($text, $word_count);

Inserts an element at a given position in an array, (*13)

$array = ['pomme', 'poire', 'fraise', 'banane'];
$array = HArray::array_insert($array, 'kiwi', 2);
Array
(
    [0] => pomme
    [1] => poire
    [2] => kiwi
    [3] => fraise
    [4] => banane
)

$array = ['pomme', 'poire', 'fraise', 'banane'];
$array = HArray::array_insert($array, ['kiwi', 'mangue'], 2);
Array
(
    [0] => pomme
    [1] => poire
    [2] => kiwi
    [3] => mangue
    [4] => fraise
    [5] => banane
)

Unit Tests

composer exec phpunit

Author

Hugo Maugey visit my website ;), (*14)

The Versions

17/03 2017

dev-master

9999999-dev

PHP Array Utilities

  Sources   Download

The Development Requires

13/03 2017

0.1

0.1.0.0

PHP Array Utilities

  Sources   Download

The Development Requires