All Projects → yiisoft → arrays

yiisoft / arrays

Licence: BSD-3-Clause license
Yii Array Helper

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to arrays

Componentarrays.jl
Arrays with arbitrarily nested named components.
Stars: ✭ 72 (+75.61%)
Mutual labels:  array, arrays
VBA-Better-Array
An array class for VBA providing features found in more modern languages
Stars: ✭ 77 (+87.8%)
Mutual labels:  array, arrays
Ubigeo-Peru
Base de datos de departamentos, provincias y distritos del Perú (UBIGEO) actualizada al 2019 (El INEI ha actualizado hasta el 2016). SQL, JSON, XML, CSV, Arreglos PHP, YAML.
Stars: ✭ 113 (+175.61%)
Mutual labels:  array, arrays
HashMapC
A tiny library for using easily HashMap, arraylist in the C.
Stars: ✭ 21 (-48.78%)
Mutual labels:  array, arrays
Cracking The Coding Interview
Solutions for Cracking the Coding Interview - 6th Edition
Stars: ✭ 35 (-14.63%)
Mutual labels:  array, arrays
Massiv
Efficient Haskell Arrays featuring Parallel computation
Stars: ✭ 328 (+700%)
Mutual labels:  array, arrays
php-collections
A collection library for php
Stars: ✭ 34 (-17.07%)
Mutual labels:  array, arrays
Pgo
Go library for PHP community with convenient functions
Stars: ✭ 51 (+24.39%)
Mutual labels:  array, arrays
Async Ray
Provide async/await callbacks for every, find, findIndex, filter, forEach, map, reduce, reduceRight and some methods in Array.
Stars: ✭ 102 (+148.78%)
Mutual labels:  array, arrays
yii-debug
Yii debug panel extension
Stars: ✭ 23 (-43.9%)
Mutual labels:  yii3
html
Handy library to generate HTML
Stars: ✭ 42 (+2.44%)
Mutual labels:  yii3
Algorithm-Implementation
This is our effort to collect the best implementations to tough algorithms. All codes are written in c++.
Stars: ✭ 16 (-60.98%)
Mutual labels:  arrays
js-deep-sort-object
Simple module to sort objects recursively by its keys
Stars: ✭ 19 (-53.66%)
Mutual labels:  array
all-about-node
All about Node.js
Stars: ✭ 16 (-60.98%)
Mutual labels:  array
avl array
High performance templated AVL tree using a fixed size array. Extensive test suite passing.
Stars: ✭ 33 (-19.51%)
Mutual labels:  array
slice
A JavaScript implementation of Python's negative indexing and extended slice syntax.
Stars: ✭ 53 (+29.27%)
Mutual labels:  arrays
interview-cookbook
A playground for learning DataStructures, Algorithms, and Object-Oriented Concepts.
Stars: ✭ 25 (-39.02%)
Mutual labels:  arrays
xml-to-array
A simple class to convert an xml to array
Stars: ✭ 30 (-26.83%)
Mutual labels:  array
yii-event
Events for Yii applications
Stars: ✭ 12 (-70.73%)
Mutual labels:  yii3
DS ALGO
Data Structures and algorithms
Stars: ✭ 20 (-51.22%)
Mutual labels:  array

Yii Arrays


Latest Stable Version Total Downloads Build status Scrutinizer Code Quality Code Coverage Mutation testing badge static analysis type-coverage

The package provides:

  • ArrayHelper that has static methods to work with arrays;
  • ArraySorter that has static methods for sort arrays;
  • ArrayAccessTrait provides the implementation for \IteratorAggregate, \ArrayAccess and \Countable;
  • ArrayableInterface and ArrayableTrait for use in classes who want to support customizable representation of their instances.

Requirements

  • PHP 7.4 or higher.

Installation

composer require yiisoft/arrays --prefer-dist

ArrayHelper usage

Array helper methods are static so usage is like the following:

$username = \Yiisoft\Arrays\ArrayHelper::getValue($_POST, 'username');

Overall the helper has the following method groups.

Getting data

  • getValue
  • getValueByPath
  • getColumn
  • getObjectVars

Setting data

  • setValue
  • setValueByPath

Removing data

  • remove
  • removeByPath
  • removeValue

Detecting array types

  • isIndexed
  • isAssociative

HTML encoding and decoding values

  • htmlDecode
  • htmlEncode

Testing against arrays

  • isIn
  • isSubset

Transformation

  • index
  • group
  • filter
  • map
  • merge
  • toArray

Other

  • keyExists
  • pathExists

ArraySorter usage

Array sorter has one static method which usage is like the following:

\Yiisoft\Arrays\ArraySorter::multisort($data, ['age', 'name'], [SORT_ASC, SORT_DESC]);

ArrayAccessTrait usage

ArrayAccessTrait provides the implementation for \IteratorAggregate, \ArrayAccess and \Countable.

Note that ArrayAccessTrait requires the class using it contain a property named data which should be an array. The data will be exposed by ArrayAccessTrait to support accessing the class object like an array.

Example of use:

use \Yiisoft\Arrays\ArrayAccessTrait;

class OfficeClassification implements \IteratorAggregate, \ArrayAccess, \Countable
{
    use ArrayAccessTrait;

    public array $data = [
        'a' => 'Class A',
        'b' => 'Class B',
        'c' => 'Class C',
    ];
}

$classification = new OfficeClassification();

echo 'Count classes: ' . $classification->count() . "\n"; // 3

$iterator = $classification->getIterator();
while ($iterator->valid()) {
    echo $iterator->current() . "\n"; // Class A, Class B, Class C
    $iterator->next();
}

ArrayableInterface and ArrayableTrait usage

ArrayableInterface and its implementation ArrayableTrait intended for use in classes who want to support customizable representation of their instances.

Example of use:

use \Yiisoft\Arrays\ArrayableTrait;
use \Yiisoft\Arrays\ArrayableInterface;

class Car implements ArrayableInterface
{
    use ArrayableTrait;

    public string $type = 'Crossover';
    public string $color = 'Red';
    public int $torque = 472;
}

$car = new Car();

$data = $car->toArray(['type', 'color']); // ['type' => 'Crossover', 'color' => 'Red']

Testing

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

Mutation testing

The package tests are checked with Infection mutation framework with Infection Static Analysis Plugin. To run it:

./vendor/bin/roave-infection-static-analysis-plugin

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

./vendor/bin/psalm

License

The Yii Arrays is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].