Download the PHP package rexlabs/array-object without Composer

On this page you can find all versions of the php package rexlabs/array-object. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package array-object

Deprecated

This library isn't in active development. Various other collection libraries provide most functionality that we need out of the box.

Bug fixes only.

Array Object

License: MIT Packagist

ArrayObject is a PHP library that provides a light-weight interface for working fluently with array's.

ArrayObject provides a wrapper around PHP's built-in array type which includes methods for filtering, and retrieving items, and conveniently treats individual items and collections as the same object.

This is especially useful for working with JSON responses from API requests.

This library is used by the Hyper Http Client to make extracting data from responses super intuitive.

Installation

Usage

The examples below are based on the follow input data.

Basics

Note: All of the methods gracefully handle treating an individual item as an array.

get($key, $default = null)

The get() method allows you to fetch the value of a property, and receive a default if the value does not exist. It also supports depth which is indicated with a .:

You can also fetch the properties using object property syntax (we overload __get() to achieve this):

getRaw($key, $default = null)

When a value fetched via get('some.key') is an array, it is boxed into an instance of ArrayObject . The getRaw() method, however, does not perform any 'boxing' on the returned value.

set($key, $value, $onlyIfExists = false)

The set() method allows you to set a property using dot notation. It will automatically create the underlying array structure:

When the $onlyIfExists flag is passed as true, it will only set that property if the key already exists.

getOrFail($key)

Similar to get() but will throw a InvalidPropertyException when the key is not found.

has($key)

To test for the existence of an element, use the has() method:

each(callback)

Looping over a collection can be acheived by passing a callback to each():

If you have a single item, it still works.

iterator

Since ArrayObject implements an Iterator interface, you can simply foreach() over the object. This works for single items or collections.

pluck($key)

Returns a new collection which contains the plucked property.

pluckArray($key)

Returns a new array of the plucked property. This provides a shortcut from pluck($key)->toArray():

count()

You can call count off any node:

Note: When called on a single item (ie. not a collection), it will return 1.

hasItems()

Returns true when the collection contains at least one item.

Note: When called on a single item (ie. not a collection), it will return true

filter(callback|array $filter)

Apply either a callback, or an array of "where" conditions, and only return items that match.

Using a callback, each item is an instance of ArrayObject:

You can also specify a list of conditions using an array:

toArray()

Getting the original array is available via the toArray() method:

toJson()

Returns a json encoded string of the underlying array:

isCollection()

Determines if the underlying array is a collection.

unshift($val[, $val...])

Adds one or more items to the start of the collection. If the array is not currently a collection it will be converted to a collection with one element.

Note: you can pass ArrayObject's as values.

shift()

Pulls the first item off the collection.
If the array is not currently a collection it will be converted to a collection with one element.

push($val[, $val...])

Adds one or more items to the end of the collection. If the array is not currently a collection it will be converted to a collection with one element.

Note: you can pass ArrayObject's as values.

pop()

Pulls the last item off the collection.
If the array is not currently a collection it will be converted to a collection with one element.

Contributing

Contributions are welcome, please submit a pull-request or create an issue. Your submitted code should be formatted using PSR-1/PSR-2 standards.

About


All versions of array-object with dependencies

PHP Build Version
Package Version
Requires rexlabs/utility-belt Version ^4.0
php Version >=7.4 <8.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rexlabs/array-object contains the following files

Loading the files please wait ....