imsamurai/arraysort

CakePHP 的数组多字段排序工具

1.0.7 2014-09-18 10:51 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:18:34 UTC


README

查看ArraySort API 文档

摘要

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

安装

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

或者如果你使用 git add 作为子模块

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

然后在 Config/bootstrap.php 中添加插件加载

CakePlugin::load('ArraySort');

用法

在代码的任何位置

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

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

其中 $array 是要排序的数组,$params 可以是字符串 ('asc' 或 'desc') 或数组,例如

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

例如

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

使用这个 $params 方法将 $array 根据排名字段排序,如果排名相同,则按创建字段排序。