Download the PHP package belt/underscore without Composer

On this page you can find all versions of the php package belt/underscore. 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 underscore

Belt.Underscore

Latest Version Build Status Coverage Status Quality Score

Pushing round things down square holes.

Belt.Underscore is an utility library that makes working with arrays in PHP a little bit more pleasant.

Installation

Via Composer

Usage

The following examples assume that you have included the Underscore utility:

Some of the examples might seem a bit contrived, but they're actually really handy. For example, let's say that we have a fictional social network and (for some reason) we want to get the names of all the authenticated user's 2nd degree friends (friends-of-friends) that are over the age of 18. Suddenly, that becomes real easy!

And now (for some even stranger reason) we want to know the total number of third degree friends (friends-of-friends-of-friends) of the 2nd degree friends that are over the age of 18.

That's it!

Note: When, in the examples, the return value comment indicates an array the actual return value is a new _ instance! You can get the actual PHP array value by calling the toArray method.

The _ class implements ArrayAccess too, so you can access it like an usual array:

Additionally, you can traverse the container in a foreach loop as well:

all

Call the given callback for each element in the container. Should the callback return false, the method immediately returns false and ceases enumeration. If all invocations of the callback return true, all returns true.

any

Call the given callback for each element in the container. Should the callback return true, the method immediately returns true and enumeration is ceased. If all invocations of the callback return false, any returns false.

chunk

Chunks the container into a new array of n-sized chunks.

combine

Combine the container with another array into key/value pairs.

concat

Returns a new array that is the container with the given array concatenated to the end.

dict

Convert an array of key/value pairs into the logical dictionary.

If you have a flat array you can call chunk(2) before dict.

each

Calls the given callback once for each element in the container, passing that element as the argument.

each also supports two and three parameter versions:

find

Passes each entry in the container to the given callback, returning the first element for which callback is not false. If no entry matches, returns null.

first

Returns the first n elements in the container.

flatten

Returns a new, one-dimensional array that is a recursive flattening of the container.

Tip: If you only want to flatten one level of an array, flatMap might be useful for you!

flatMap

Returns a new array with the concatenated results of invoking the callback once for every element in the container.

It might look a bit silly, but this is actually a really useful function when you combine it with other functions! For example, you can create a dictionary for (fictional) users.

Which finally allows us, as developers, to create key/value pairs when mapping arrays! Hoorah!

groupBy

Groups the container by result of the given callback.

has

indexOf

Returns the index of the given object in the container or null if the element was not found.

inject

Combines all elements of the container by applying a binary operation.

Note: This is the only exception to the note earlier. The return value here is the return value of the last itertation.

join

Returns a string of all the container's elements joined with the provided separator string.

last

Returns the last n elements from the container.

map

Invokes the given callback for each element in the container. Creates a new array containing the values returned by the block.

If the given callback returns null, that element is skipped in the returned array.

max

Returns the element for which the given callback returns the largest integer.

min

Returns the element for which the given callback returns the smallest integer.

none

Test if the given callback returns false for each element in the container.

partition

Partitions the container into two arrays based on the boolean return value of the given block.

pluck

Returns a new array that is the result of retrieving the given property path on each element in the container.

product

Calculate the product of the container by assuming that all values can be casted to a double value.

reduce

Reduces the container to a single value.

The usual example of reduce is to sum all values in an array.

Reduce also allows you to set an initial value before reducing the array.

reject

Returns a new array containing all elements for which the given callback returns false.

reverse

Returns a new array that is the container, reversed.

rotate

Returns a new array rotated about the provided index.

sample

Returns a random element from the container.

select

Returns a new array containing all elements for which the given block returns true.

shuffle

Returns a new array that is shuffled.

skip

Skips the first n elements and returns the rest of the array.

slice

Returns a subarray consisting of the given number of elements from the given starting index.

snip

Snips the end off the array. Returns the container without the last n elements.

sort

Returns the container, sorted.

sortBy

Sorts all objects using the return value of the given callback as the sorting criteria.

sum

Sum all objects by casting the values to a double.

transpose

Assumes that the container is an array of arrays and transposes the rows and columns.

uniq

Returns a new array by removing duplicate values in the container.

without

Returns a new array where objects in the given array are removed from the container.

pop

Treats container like a stack and removes the last object, returning it.

push

Treats container like a stack and adds the given object to the end of the container.

shift

Removes the container's first object and returns it.

unshift

Inserts the given object at the front of container, moving all other objects in the container up one index.

split

Returns a new array of the strings in the given string that are separated by the given separator.

The second parameter is optional and null by default, if you pass null or an empty string as seperator, you will get an array of the individual characters in the given string.

We can do some pretty neat stuff with this!

first, last, skip, snip & slice

These functions are strongly related and useful to remember.

Contributing

Please see CONTRIBUTING.

Credits

This project is heavily inspired by YOLOKit. For all of you who develop in Objective-C, I highly recommend you check it out!

License

Please see LICENSE.


All versions of underscore with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
symfony/property-access Version ~2.0
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 belt/underscore contains the following files

Loading the files please wait ....