Download the PHP package tuck/sort without Composer

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

Tuck\Sort

Build Status Latest Stable Version Total Downloads License

Syntactic sugar for PHP's built in sorting.

Examples

Basic sorting functions

Why?

This library tries to smooth out the built-in API, specifically the following issues:

PHP requires variables.

If you want to sort the result of a method, you need to assign it to an intermediate variable.

With this library, you can pass results directly:

PHP modifies in-place

Perhaps you'd prefer sort to return a modified list, rather than mutating the original. Unfortunately, the return value of is a success boolean, not the reordered list.

With this library, the results are returned directly and the original list is not modified:

PHP's naming is confusing

PHP's sorting functions don't always have the most intuitive names:

With this library, naming reads a little better:

PHP doesn't handle keys consistently

When you use PHP discards the original keys. Unless you use . Or and which always preserve the original keys. You get the idea.

With this library, the returned keys are reset to sequential numbers, regardless of the type of sorting.

If you'd like to keep the original keys, there's a consistent parameter you can always use . This selects the correct key-preserving function under the hood, so you don't have to remember it.

This works for all sort functions:

Much easier to remember. If the constants are too long-winded or readable, you can also pass to preserve the keys or to discard them.

PHP doesn't accept iterators or generators

Built-in sorting functions work great on arrays but won't accept their Traversable brethren.

With this library, iterators and generators are automatically converted to arrays.

Note this library always returns arrays, even when given a custom collection. If you'd like your custom collection to support this library, see the usort documentation below.

PHP doesn't have a shorthand for sorting by fields

When you're comparing a list of objects, you usually want to compare the same field on them repeatedly. Usually that means writing a usort function like this:

And that's with the PHP 7 shorthand operator helping. This library offers a slightly shorter, Scala inspired version where you only specify how to retrieve the sortable data from an element.

This also works in reverse:

PHP doesn't have chained usort

There's no elegant syntax for chaining multiple sorts at once. If you wanted to sort a list of high scores, first by points, then name, then date, you'd need to write a function like:

With this library, you can chain sorts like so:

In most cases, you'll want to extract the same information from and at the same time. You might also want to sort them as ascending or descending on different factors. For both of these use cases, you can use the and methods.

Once you've created your sorting chain, you can apply it to keys or values. Features like Iterator support, returned values, and PRESERVE_KEY flag are all supported.

You can also invoke the chain itself as a comparison function:

This means you can use it with any custom collection class that supports usort:

When building your sort chain, you don't have to compose all the sorting functions at once. You can attach them over time or conditionally:

However, if use the chain before any sorts are added, then the order is essentially random and decided by your PHP runtime (PHP 5.x vs PHP 7 vs HHVM). There's no easy way to normalize this (I've tried) but it varies based on the runtime, the number of elements in the array, the sorting algorithm used, etc. The good news is it doesn't matter if the elements are random because there was nothing worth sorting by anyways! :)

License

MIT

Contributing

PRs welcome. :) Please abide by PSR-2, use tests, and respect the Code Manifesto.

Status

Working, tested, still need to add non-functionals like docs and fancy README badges.


All versions of sort with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 tuck/sort contains the following files

Loading the files please wait ....