varaey/strategy

Maintainers

Details

github.com/varaey/sorter

Source

Issues

Installs: 9

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/varaey/strategy

1.0.1 2019-05-07 17:48 UTC

This package is auto-updated.

Last update: 2025-12-08 08:38:40 UTC


README

This is a sorter library. This library use strategy pattern for sorting string or number array.

Installation

$ composer require varaey/strategy

Next step is:

Usage

<?php

$array_char = ['f', 'a', 'b', 'd', 'c'];
$array_number = [8, 3, 4, 7, 1, 2, 5, 9, 6];


$sort = new Sorter(new StrategyFirstToLast());
echo 'Start sorting (From First to Last)' . \PHP_EOL;
\print_r($sort->sort($array_char));
\print_r($sort->sort($array_number));

echo \PHP_EOL;

echo 'Start sorting (From Last to First)' . \PHP_EOL;
$sort->setStrategy(new StrategyLastToFirst());
\print_r($sort->sort($array_char));
\print_r($sort->sort($array_number));

echo \PHP_EOL;

echo 'Start sorting (nulll object)' . \PHP_EOL;
$sort->setStrategy(new NullObjectSort());
\print_r($sort->sort($array_char));
\print_r($sort->sort($array_number));

License

license

This project is released under the terms of the BSD-3-Clause license.

Copyright (c) 2019, Svitozar Kuzemskyi