Skip to content

Releases: pdscopes/php-arrays

v3.0.0

19 Aug 08:05
Compare
Choose a tag to compare

A new major version that does the following things:

  • Renames default branch to main
  • Minimum PHP increased to 7.4
  • Makes library compatible with PHP 8
  • Adds stricter typing (where appropriate)

Full Changelog: v2.1.0...v3.0.0

Minimum PHP increased to 7.1

25 Feb 14:54
e0b921a
Compare
Choose a tag to compare
v2.1.0

adds github actions to run tests and upgrades to php>=7.1 and phpunit…

Renamed function names

16 May 09:06
Compare
Choose a tag to compare
  • Renamed functions to sit in line with php function names:

    • Arr::findKey -> Arr::searchKey
    • Arr::find -> Arr::search
    • ArrDots::search -> ArrDots::collate
    • Collection::find -> Collection::search
  • Added Arr::pluck and ArrDots::pluck switch combines column and collapse

v1.3.5

11 May 11:41
Compare
Choose a tag to compare

Arr and ArrDots

Arr::locate and ArrDots::locate
Given a multi-dimensional array, return the first item that has a property $property with value $value. An array of properties can be provided to perform deeper finds.

v1.3.4

11 May 10:54
Compare
Choose a tag to compare

Arr

Arr::column Get the values from a single column in $array. An array of columns can be provided to chain call column.
Arr::collapse Merge all elements of $array into a single array.

ArrDots

ArrDots::column Get the values from a single column in $array. Dots notation can be provided to chain call column.

v1.3.3

15 Sep 11:04
Compare
Choose a tag to compare

Arr

Added Arr::findKey and Arr::find

Collection

Added Collection::slice, Collection::find, Collection::implode.
Significantly improved the performance of Collection::nth.
Removed Collection::toJson

Arrayable interface, Collection class, new functions for Arr class

08 Sep 10:19
Compare
Choose a tag to compare

Added Arrayable interface

Arrayable interface defines a simple function that should convert an instance into an array.

Added Collection class

A Collection is way to interact with an array as an object. It provides many of the methods available in Arr.

New function in Arr

Two new functions have been added to Arr:
1 Arr::filter: supply a callable and the array will be filter to only contain values that return true
2 Arr::except: the opposite of only, leaves all items in the array except those keys provided.

New method: ArrDots::search

30 Aug 08:45
Compare
Choose a tag to compare

ArrDots::search is a new method that, given a key with possible wildcards, will return an associative array of all matching dot notations to their values. For example:

$data = [
    'field0' => 'field0-value',
    'array0' => [1, 2, 3, 4],
    'array1' => [
        ['item0' => 'item0-value'],
        ['item0' => 'item1-value'],
    ],
    'array2' => [
        ['sub-array0' => [1, 2, 3, 4]],
        ['sub-array0' => [1, 2, 3, 4]],
    ],
    'array3' => [
        ['sub-array1' => [['item1' => 'item2-value'], ['item1' => 'item3-value']]],
        ['sub-array1' => [['item1' => 'item4-value']]],
    ],
];

// Simple
$results = ArrDots::search($data, 'field0');
$results === [
    'field0' => 'field0-value
];

// End with wildcard
$results = ArrDots::search($data, 'array0.*', '*');
$results === [
    'array0.0' => 1,
    'array0.1' => 2,
    'array0.2' => 3,
    'array0.3' => 4,
];

// Single wildcard inside
$results = ArrDots::search($data, 'array2.*.sub-array0', '*');
$results === [
    'array2.0.sub-array0' => [1, 2, 3, 4],
    'array2.1.sub-array0' => [1, 2, 3, 4],
];

// Multiple wildcard
$results = ArrDots::search($data, 'array3.*.sub-array1.*.item1', '*');
$results === [
    'array3.0.sub-array1.0.item1' => 'item2-value',
    'array3.0.sub-array1.1.item1' => 'item3-value',
    'array3.1.sub-array1.0.item1' => 'item4-value',
];

PHP Array Helpers

30 Aug 08:49
Compare
Choose a tag to compare

This is a new library of helper functions for php arrays/ArrayAccess. We release with 3 classes Arr, ArrDots, and Dots.
Arr is full of functions for array/ArrayAccess objects.
ArrDots is full of functions for "dot notation" access of array/ArrayAccess objects.
Dots is an implementation of ArrayAccess that with functions to set the underlining array as a copy or a reference.