imsamurai/arraysort

CakePHP utility for sorting arrays by multiple fields

Maintainers

👁 imsamurai

Package info

github.com/imsamurai/cakephp-arraysort-utility

Homepage

Type:cakephp-plugin

pkg:composer/imsamurai/arraysort

Statistics

Installs: 3 072

Dependents: 2

Suggesters: 0

Stars: 2

Open Issues: 0

1.0.7 2014-09-18 10:51 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 0bb61b2381c0005f2f03d3c0a25e43be96bf2589

plugincakephparraysort

This package is not auto-updated.

Last update: 2026-06-21 00:07:25 UTC


README

Check out ArraySort API Documentation

Abstract

👁 Build Status
👁 Coverage Status
👁 Latest Stable Version
👁 Total Downloads
👁 Latest Unstable Version
👁 License

Installation

cd my_cake_app/app
git clone git://github.com/imsamurai/cakephp-arraysort-utility.git Plugin/ArraySort

or if you use git add as submodule:

cd my_cake_app
git submodule add "git://github.com/imsamurai/cakephp-arraysort-utility.git" "app/Plugin/ArraySort"

then add plugin loading in Config/bootstrap.php

CakePlugin::load('ArraySort');

Usage

In any place of your code:

App::uses('ArraySort', 'ArraySort.Utility');

$sorted_array = ArraySort::multisort($array, $params);

where $array is array to sort, $params can be string ('asc' or 'desc') or array like this:

$params = array(
 <field1> => <direction>,
 <field2> => <direction2>,
 ...
);

For example:

$params = array(
 'rank' => 'desc',
 'created' => 'asc'
);

With this $params method will sort $array by comparing each elements firstly by rank field, if they have equal rank then sort by created field.