定制 arifulhb/php-algorithms 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

arifulhb/php-algorithms

Composer 安装命令:

composer require arifulhb/php-algorithms

包简介

Multi-dimensional Array & Object Sorting in PHP

README 文档

README

Sort a multidimensional array or object by String or integer or both types.

Installation

Install the package on your php application.

composer require arifulhb/php-algorithms

Sort by Array

For example, if you have an array, and you want to sort by name or by price or both, you can use this package to sort.

 $items = [
    [
        'name' => 'computer',
        'price' => 4,
    ],
    [
        'name' => 'tv',
        'price' => 9,
    ],
    [
        'name' => 'apple',
        'price' => 1,
    ],
    [
        'name' => 'airpod',
        'price' => 1,
    ],
    [
        'name' => 'airtag',
        'price' => 3,
    ],
    [
        'name' => 'shampoo',
        'price' => 5,
    ]
];

How to

// create a configuration object specifying integer and string field accordingly.
$config = new SortConfiguration('price', 'name');

// create sort object with the configuration
$sortArray = new SortArray($config);

// sort the array
$result = $sortArray->sort($products);

Sort by Object

Same as sort by array, but here you may have an array of object to sort. For example,

$arrayOfObjects = [
    new Product('computer', 4),
    new Product('tv', 9),
    new Product('apple', 1),
    new Product('airpod', 1),
    new Product('airtag', 3),
    new Product('shampoo', 5)
];

How to

// create a configuration object specifying integer and string field accordingly.
$config = new SortConfiguration('price', 'name');

// create sort object with the configuration
$sortObject = new SortObject($config);

// sort the array
$result = $sortObject->sort($products);

Development

To run the test cases,

composer run-script tests

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固